使用Spring+Junit4.4进行测试
http://nottiansyf.iteye.com/blog/345819
使用Junit4.4测试
在类上的配置Annotation
@RunWith(SpringJUnit4ClassRunner.class) 用于配置spring中测试的环境
@ContextConfiguration(locations={"classpath:spring/applicationContext.xml","classpath:spring/spring-config-*.xml"})用于指定配置文件所在的位置
@Test标注在方法前,表示其是一个测试的方法 无需在其配置文件中额外设置属性.
多个配置文件时{"/applic","/asas"} 可以导入多个配置文件
WEB-INF/classes/spring/beanRefContext.xml配置路径:classpath:spring/beanRefContext.xml
测试中的事务配置 ,
AbstractTransactionalJUnit38SpringContextTests、 AbstractTransactionalJUnit4SpringContextTests
AbstractTransactionalTestNGSpringContextTests
已经在类级别预先配置了好了事物支持
在普通spring的junit环境中配置事务
在类之前加入注解
@TransactionConfiguration(transactionManagert="txMgr",defaultRollback=false)
@Transactional
在方法中主要使用的Annotation包括
@TestExecutionListeners({})---用于禁用默认的监听器 否着需要通过@contextconfiguration配置一个ApplicationContext;
@BeforeTransaction
@Before
@Rollback(true)
@AfterTransaction
@NotTransactional
Junit4.4下支持类,方便基于junit4.4的测试
AbstractJUnit4SpringContextTests:
AbstractTransactionalJUnit4SpringContextTests:
需要在applicationContext中定义一个datasource
2009年3月9日
目前Spring2.5只支持4.4的Junit进行测试
下面是一个简单的测试Demo
- package cn.com.bhgx.business.module.customerinfo.test;
- import javax.annotation.Resource;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.transaction.TransactionConfiguration;
- import org.springframework.transaction.annotation.Transactional;
- import cn.com.bhgx.business.module.customerinfo.service.ICustomerService;
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations={"classpath:spring/web-application-common.xml","classpath:spring/web-application-dao.xml","classpath:spring/web-application-service.xml"})
- @TransactionConfiguration(transactionManager="transactionManager",defaultRollback=false)
- @Transactional
- public class TestAllFunction {
- @Resource(name="customerService")
- private ICustomerService customerService;
- @Test
- public void getAllCustomers() {
- customerService.getCustomerById("1241470");
- }
- }
使用Spring+Junit4.4进行测试的更多相关文章
- 使用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- 用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- 使用 Spring 2.5 TestContext 测试框架
Spring 2.5 TestContext 测试框架用于测试基于 Spring 的程序,TestContext 测试框架和低版本 Spring 测试框架没有任何关系,是一个全新的基于注解的测试框架, ...
- Spring框架下Junit测试
Spring框架下Junit测试 一.设置 1.1 目录 设置源码目录和测试目录,这样在设置产生测试方法时,会统一放到一个目录,如果没有设置测试目录,则不会产生测试代码. 1.2 增加配置文件 Res ...
- Spring Boot应用的测试——Mockito
Spring Boot应用的测试——Mockito Spring Boot可以和大部分流行的测试框架协同工作:通过Spring JUnit创建单元测试:生成测试数据初始化数据库用于测试:Spring ...
- Spring Junit4 接口测试
Junit实现接口类测试 - dfine.sqa - 博客园http://www.cnblogs.com/Automation_software/archive/2011/01/24/1943054. ...
- spring boot项目如何测试,如何部署
有很多网友会时不时的问我,spring boot项目如何测试,如何部署,在生产中有什么好的部署方案吗?这篇文章就来介绍一下spring boot 如何开发.调试.打包到最后的投产上线. 开发阶段 单元 ...
- Spring、Spring Boot和TestNG测试指南 - 使用Spring Boot Testing工具
Github地址 前面一个部分讲解了如何使用Spring Testing工具来测试Spring项目,现在我们讲解如何使用Spring Boot Testing工具来测试Spring Boot项目. 在 ...
- Spring Boot中的测试
文章目录 简介 添加maven依赖 Repository测试 Service测试 测试Controller @SpringBootTest的集成测试 Spring Boot中的测试 简介 本篇文章我们 ...
随机推荐
- ●BZOJ 1692 [Usaco2007 Dec]队列变换
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1692 题解: 后缀数组,贪心由于每次可以取出旧队列的首部或尾部放在新队列的尾部.所以就需要比 ...
- [Noi2013]矩阵游戏
来自FallDream的博客,未经允许,请勿转载,谢谢. 婷婷是个喜欢矩阵的小朋友,有一天她想用电脑生成一个巨大的n行m列的矩阵(你不用担心她如何存储).她生成的这个矩阵满足一个神奇的性质:若用F[i ...
- (MariaDB/MySQL)之DML(2):数据更新、删除
本文目录:1.update语句2.delete语句 2.1 单表删除 2.2 多表删除3.truncate table 1.update语句 update用于修改表中记录. # 单表更新语法: UPD ...
- 某些情况下调用函数为什么要在函数名前加“(void)”
我们知道,在定义函数时,加在函数名前的"void"表示该函数没有返回值.但在调用时,在函数名前加"(void)"的作用又是什么呢? 最明显的一点就是表示程序并不 ...
- HTML中鼠标滚轮事件onmousewheel处理
滚轮事件是不同浏览器会有一点点区别,一个像Firefox使用DOMMouseScroll ,ff也可以使用addEventListener方法绑定DomMouseScroll事件,其他的浏览器滚轮事件 ...
- ubuntu 卸载从源码安装的 emacs
由于配置问题想卸了重装. 解压并进入你的源码所在目录: ./configure sudo make uninstall Done Reference: http://askubuntu.com/que ...
- 学习ASP.NET Core Razor 编程系列七——修改列表页面
学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...
- Web API对application/json内容类型的CORS支持
假设有一简单架构分为前后两部分,其一是Angular构成的前端页面站点,另一个则是通过ASP.NET Web API搭建的后端服务站点.两个站点因为分别布署,所有会有CORS(Cross-Origin ...
- E1
en表"使怎么样" engage 吸引,从事,订婚 be engaged in doing sth. 忙于 endure 忍耐,忍受 enforce 强制执行 enrol ...
- 好IT男不能“淫”-谈IT人员目前普遍存在的“A情绪”
<如果当道德无法约束你的时候...那么就让对疾病的恐惧来制约你吧> 前言 在写这篇文章前我的心情无比的沉重.几次提笔欲写,几次又未能完成,可是最终让我"奋笔疾书"的原因 ...