使用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中的测试 简介 本篇文章我们 ...
随机推荐
- 51nod 1035:最长的循环节
1035 最长的循环节 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 正整数k的倒数1/k,写为10进制的小数如果为无限循环小数,则存在一个循环节,求< ...
- 【bzoj4568 scoi2016】幸运数字
题目描述 A 国共有 n 座城市,这些城市由 n-1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个幸运数字,以纪念碑的形式矗立在这座城市的正中心,作为城市的象征. 一些旅行者希望 ...
- SPOJ 7258 Lexicographical Substring Search
Little Daniel loves to play with strings! He always finds different ways to have fun with strings! K ...
- VB6工程在Win10系统打开提示MSCOMCTL.OCX无法加载
解决办法: 修改.vbp文件中的 00F8754DA1}#2.1#0; MSCOMCTL.OCX 改为 00F8754DA1}#2.0#0; MSCOMCTL.OCX 中间的2.1 改为 2.0
- C++ 实参和形参
形参:在函数没有调用的时候,函数的形参并不占据实际的内存空间,也没有实质的值,--正如字面意思那样,"形式"参数,只是一个"形式. 实参:当函数被调用的时候,系统会为形式 ...
- 解决nodejs中json序列化时Date类型默认为UTC格式
在nodejs中,json序列化时Date类型时,默认转为UTC格式. 如下图 上面只是一个例子,下面我用一个更具体化的例子来展示一个这个情况,我们在开发WEB项目中,经常用到Express组件, 我 ...
- VMWare - Ubuntu 64 (16.04)之扩容介绍
背景 貌似是一个老生常谈的问题哈,由于自己之前也没有弄过,今天正好有时间稍微折腾了一下. 这里就选择最简单的方式来为大家呈现. VMWare 的设置 没有什么可以过多说的,完全是图形操作.这里直接上图 ...
- mybatis choose标签的使用
MyBatis 提供了 choose 元素.if标签是与(and)的关系,而 choose 是或(or)的关系. choose标签是按顺序判断其内部when标签中的test条件出否成立,如果有一个成立 ...
- Ubuntu 16.04LTS 安装 MATLAB 2014B
环境:Ubuntu 16.04LTS 软件:MATLAB 2014B MATLAB 2014B 下载地址(带Crack): 链接: https://pan.baidu.com/s/1nvGtmEd 密 ...
- 背包DP入门小笔记01背包
FJUT OJ 2347 http://59.77.139.92/Problem.jsp?pid=2347 采药 TimeLimit:1000MS MemoryLimit:128MB 64-bit ...