当前位置: 代码迷 >> Web前端 >> junit4使用以及和spring的整合
  详细解决方案

junit4使用以及和spring的整合

热度:184   发布时间:2012-11-23 22:54:33.0
junit4应用以及和spring的整合
junit3
就加载junit3对应的jar包就可以
测试类需要继承junit.framework.TestCase
重写setup方法在setup加载需要的配置文件
测试方法需要以test开头testMyCase()


junit4
依赖的jar:org.hamcrest.core.jar  junit4.jar
只需要测试方法加org.junit.Test注解
或者按照3的规范继承junit.framework.TestCase并规范命名测试方法即可



和spring的整合
参考:http://blog.csdn.net/mumuzhu2011/article/details/7704120
依赖org.springframework.test.jar包

@org.junit.runner.RunWith(SpringJUnit4ClassRunner.class)
@org.springframework.test.context.ContextConfiguration
(locations = "classpath:applicationContext.xml")
public class ConsumerTest extends org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
{
        @Resource
IConsumerDAO consumerDAOImpl;

//@Test
public void testAbc() {
System.out.println(consumerDAOImpl.getConsumer(1).getUserName());

}
}
手动加载spring配置文件 http://jie66989.iteye.com/blog/1699622

原文地址:http://jie66989.iteye.com/blog/1699640
  相关解决方案