@ContextConfiguration(locations = "classpath:conf/applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public abstract class AbstractTestCase extends
AbstractTransactionalDataSourceSpringContextTests { }

将配置项都写在父类中,测试子类继承该AbstractTestCase类,测试的时候,不会导致数据库数据污染,因为继承AbstractTransactionalDataSourceSpringContextTests每次数据库操作完成之后都会回滚。

例如:

public class TransFlowServiceTests extends AbstractTestCase {
@Autowired
TransFlowService transFlowService; @Test
public void testQueryTransFlow() {
Map map = new HashMap();
PageBean pb = new PageBean(1, 20, 10);
map.put("pb", pb);
List<TransFlow> lis = transFlowService.queryTransFlow(map);
for (TransFlow tf : lis) {
System.out.println(tf.getOrderNo() + "-" + tf.getStatus() + "-" + tf.getStatusView() + "-" + tf.getOrderTime() + "-" + tf.getOrderTimeView());
}
} @Test
public void testGetTransFlowCount() {
Map map = new HashMap();
PageBean pb = new PageBean(1, 20, 10);
map.put("pb", pb);
int i = transFlowService.getTransFlowCount(map);
System.err.println("i="+i);
} @Test
public void testGetTransFlowNum() {
int j = transFlowService.getTransFlowNum();
System.out.println("j="+j);
} @Test
public void testUpdateTransFlowStatus() {
int k = transFlowService.updateTransFlowStatus();
System.err.println("k="+k);
} }

spring测试父类,使用junit-4.4.jar,spring-test.jar的更多相关文章

  1. Spring入门(二)— IOC注解、Spring测试、AOP入门

    一.Spring整合Servlet背后的细节 1. 为什么要在web.xml中配置listener <listener> <listener-class>org.springf ...

  2. 一个简单的Spring测试的例子

    在做测试的时候我们用到Junit Case,当我们的项目中使用了Sring的时候,我们应该怎么使用spring容器去管理我的测试用例呢?现在我们用一个简单的例子来展示这个过程. 1 首先我们新建一个普 ...

  3. 最“高大上”的Spring测试:Spring Test

    我想给大家介绍一款非常实用.且高端大气上档次的spring测试,在这里,我要强烈推荐使用Spring的Test Context框架,为什么呢?俗话说,“货比三家不上当”,要搞清楚这个问题,我们先来看一 ...

  4. Spring-----注解开发和Spring测试单元

    一.注解开发 导入jar包;spring-aop-xxx.jar 导入约束:(在官方文档xsd-configuration.html可找) <beans xmlns="http://w ...

  5. Spring Boot入门学习,解决复杂的spring配置文件及jar包

    转载:https://www.cnblogs.com/wmyskxz/p/9010832.html 总结 为何出了这样的框架? Spring Boot 是所有基于 Spring 开发的项目的起点.Sp ...

  6. Java开发学习(十四)----Spring整合Mybatis及Junit

    一.Spring整合Mybatis思路分析 1.1 环境准备 步骤1:准备数据库表 Mybatis是来操作数据库表,所以先创建一个数据库及表 create database spring_db cha ...

  7. spring中各jar功能及jar包之间的依赖关系

    (1) spring-core.jar 这个jar文件包含Spring框架基本的核心工具类,Spring其它组件要都要使用到这个包里的类,是其它组件的基本核心,当然你也可以在自己的应用系统中使用这些工 ...

  8. SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active

    趁今天有时间整理了一下 启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 jav ...

  9. 详解intellij idea搭建SSM框架(spring+maven+mybatis+mysql+junit)(下)

    在上一篇(详解intellij idea 搭建SSM框架(spring+maven+mybatis+mysql+junit)(上))博文中已经介绍了关于SSM框架的各种基础配置,(对于SSM配置不熟悉 ...

随机推荐

  1. 20140912-关于.NET技术体系的思维导图

    逛园子时看到的. 关于.NET技术体系的思维导图

  2. C语言清除输入缓存方法记录[转]

    原文:http://www.tomytime.com/archives/218/ fflush()函数是标准的作法. setbuf(stdin,NULL)是GCC下可用的一种方法. scanf(&qu ...

  3. 【转】Javascript 中的false,零值,null,undefined和空字符串对象

    js 开发中经常会碰到判断是否为空的情况,关于 null 和 undefined 的区别了解的不是很好,刚好看见这篇文章,转过来学习一下,以下是转载正文: 在Javascript中,我们经常会接触到题 ...

  4. EF调用函数日期查询

    q = q.Where(t => System.Data.Entity.SqlServer.SqlFunctions.DateDiff("dd", t.Date, dDate ...

  5. 【风马一族_Android】强制activity的横屏与纵屏

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...

  6. SQL联合查询中的关键语法(转)

    联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用户名,密码)    userid int         username   varchar(20)     password      ...

  7. Android 悬浮窗 WindowManager WindowManager.LayoutParamas

    前方高清大图~~~~ 绘制的图片资源: // draw bitmap BitmapDrawable bmpDraw = (BitmapDrawable) getResources().getDrawa ...

  8. 学习php中常用语句与函数

    1.while循环多用于不清楚循环次数的情况下,如需要把从数据库中读取出的多条记录(不清楚到底有多少条)并且要根据某个字段的值进行分类,每类值的具体数目,如下图: 其中选项有三种值,对每个值的票数时行 ...

  9. Microsoft Virtual Academy 介绍

    Microsoft Virtual Academy 是微软的虚拟学院,会推出微软各个方面的一些教程 介绍一点有用的链接 http://www.microsoftvirtualacademy.com/e ...

  10. 命令行参数的处理函数getopt

    命令参数 在linux下, shell命令的参数分两种情况: a.参数需要附加信息, 如"wget http://www.abc.com/1.zip -o 1.zip" b.参数不 ...