protected void onSetUp() throws Exception {
super.onSetUp();
SessionFactory sf = (SessionFactory) applicationContext.getBean("sessionFactory");
session = sf.getCurrentSession();
assertNotNull(session);
MailTemplateFactory.init();
}
protected void onTearDown() throws Exception {
super.onTearDown();
MailTemplateFactory.clear();
}
1.AbstractSpringContextTests:spring中使用spring上下文测试的Junit扩展类,我们一般不会使用这个类来进行单元测试,它是spring内部设计使用到的类
2.AbstractDependencyInjectionSpringContextTests:这是AbstractSpringContextTests的直接子类,支持依赖spring上下文的测试类,这个类不支持事务。
3.AbstractTransactionalSpringContextTests(我们主要继承这个):这是 AbstractDependencyInjectionSpringContextTests的直接子类,这个类一般应用在事务相关的测试中,一旦完成每个测试它就会正常地回滚事务,不会真正更新数据库,若要手动设置事务相关操作,你可以重载onSetUpInTransaction和 onTearDownInTransaction方法,以便手工开始并提交事务,或者调用setComplete()方法。这个类也可以在没有事务的情况下,使用这个类。
4.AbstractTransactionalDataSourceSpringContextTests:这是 AbstractTransactionalSpringContextTests的直接子类,它使用了Spring的基于JDBC的 jdbcTemplate工具类,支持数据库级别的事务。
对于上面第三个,如果不想事务回滚的话,就调用this.setComplete()可以了;
分享到:
相关推荐
使用spring 和junit的一个小案例,用来了解如何使用spring和junit4。入门级
Spring3+junit的单元测试的代码示例。
基于Spring的JUnit4单元测试
NULL 博文链接:https://zkf60553.iteye.com/blog/1604723
由于很多人不会配置Junit4和spring boot集成,所以文档主要讲解spring boot Junit4配置
基于Spring的JUnit4单元测试
NULL 博文链接:https://zgdeng.iteye.com/blog/1776487
spring接管JUnit.txt
oesoft_spring_junit
spring3 junit 测试 + word文档,里面的例子能直接运行.
Spring整合JUnit示例Demo,具体参照文章 http://blog.csdn.net/stemq/article/details/53291919
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2292739
Spring 提供Junit4的支持测试Demo.
Spring整合Junit框架进行单元测试Demo 详细参考: http://blog.csdn.net/stemq/article/details/53291919
hibernate+spring+junit+ant+mysql 小实例。能够当模板
struts-junit spring-mock spring-test junit等的javadoc.jar格式的API文档,直接导入Eclipse/MyEclipse/Netbeans等IDE即可实现快速API查询。 包含以下文件: File name -------------------------------------- ...
基于注解的IOC配置,Spring整合Junit_特别适合新手学习。
单元测试—— Spring 环境下测试,所需要的jar包: spring-test-4.3.29.RELEASE.jar、junit-4.13.1.jar、hamcrest-core-1.3.jar。
接管JUnit资源是指Spring框架为了方便进行单元测试,在测试类中提供了自动装配和依赖注入的功能,使得测试类能够轻松地使用Spring容器中的Bean和依赖。这样,我们可以在测试类中使用Spring的依赖注入机制来注入所需...
NULL 博文链接:https://364232252.iteye.com/blog/2369962