SSM 创建一个测试类 Junit Test

Posted 有态度的麦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSM 创建一个测试类 Junit Test相关的知识,希望对你有一定的参考价值。

package yourMvc;

import javax.annotation.Resource;
import org.junit.Test;
import org.apache.log4j.Logger;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.alibaba.fastjson.JSON;
import com.maimai.pojo.Student;
import com.maimai.service.IStudentService;


@RunWith(SpringJUnit4ClassRunner.class) //表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations = { "classpath:spring-mybatis.xml" })

public class TestStudent {
    private static Logger logger = Logger.getLogger(TestStudent.class);
    @Resource
    private IStudentService studentService = null;
    @Test
    public void studentTest() {
        Student student = studentService.getStudentById(1);
        logger.info(JSON.toJSONString(student));
    }
}

run as JUnit Test

结果

[yourMvc.TestStudent] - {"age":24,"id":1,"password":"123456","userName":"麦麦"}

 

参考博客

http://blog.csdn.net/zhshulin/article/details/37956105#

http://blog.csdn.net/zhshulin/article/details/23912615

待参考博客

http://blog.csdn.net/loginandpwd/article/details/74157210

以上是关于SSM 创建一个测试类 Junit Test的主要内容,如果未能解决你的问题,请参考以下文章

第一节——Junit单元测试

JUnit单元测试基础要点

Spring之junit测试集成

junit测试

JUnit单元测试

JUnit测试