spring测试框架的使用
junit的使用
1、加入 junit jar包
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
2、标注@Test注解、调用测试框架方法、调用 httpclient 方法
Assert.assertNotNull(user);
Assert.assertNull(user.getId());
Assert.assertTrue(userList.size() > 0);
Assert.assertEquals("admin", user.getUserName());
junit、spring-test 的使用
1、加入 junit 及 spring-test jar包
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
2、在测试类上添加注解,并指定spring配置文件的classpath
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/spring-context.xml") //@ContextConfiguration(classes=xxx.class)
public class TestJedis { }
3、标注@Test注解、调用测试框架方法、调用 httpclient 方法(同上)
junit、pring-test 的网络使用示例
@ContextConfiguration(locations = "classpath:conf/applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public abstract class AbstractTestCase extends
AbstractTransactionalDataSourceSpringContextTests { }
将配置项都写在父类中,测试子类继承该AbstractTestCase类,测试的时候,不会导致数据库数据污染,因为继承AbstractTransactionalDataSourceSpringContextTests每次数据库操作完成之后都会回滚。
spring测试框架的使用的更多相关文章
- Spring测试框架JUnit4.4 还蛮详细的
TestContext 可以运行在 JUnit 3.8.JUnit 4.4.TestNG 等测试框架下. Spring的版本2.5+JUnit4.4+log4j1.2.12 @RunWith(Spri ...
- Spring 测试框架testContext代码举例
import javax.annotation.Resource; import org.junit.Test; import org.springframework.context.annotati ...
- 使用 Spring 2.5 TestContext 测试框架
Spring 2.5 TestContext 测试框架用于测试基于 Spring 的程序,TestContext 测试框架和低版本 Spring 测试框架没有任何关系,是一个全新的基于注解的测试框架, ...
- Spring TestContext测试框架搭建
同样是测试,JUnit和Spring TestContext相比,Spring TestContext优势如下: 1.Spring TestContext可以手动设置测试事务回滚,不破坏数据现场 2. ...
- Spring-Context之二:使用Spring提供的测试框架进行测试
Spring框架是无侵入性的,所以你的代码可以完全是POJO(plain old java object),直接使用Junit就可以完成大部分的单元测试.但是在集成测试方面就比较吃力了.单元测试层面你 ...
- 原创:Spring整合junit测试框架(简易教程 基于myeclipse,不需要麻烦的导包)
我用的是myeclipse 10,之前一直想要用junit来测试含有spring注解或动态注入的类方法,可是由于在网上找的相关的jar文件进行测试,老是报这样那样的错误,今天无意中发现myeclips ...
- Spring MVC测试框架
原文链接:http://jinnianshilongnian.iteye.com/blog/2004660 Spring MVC测试框架详解——服务端测试 博客分类: springmvc杂谈 spri ...
- Spring MVC测试框架详解——服务端测试
随着RESTful Web Service的流行,测试对外的Service是否满足期望也变的必要的.从Spring 3.2开始Spring了Spring Web测试框架,如果版本低于3.2,请使用sp ...
- spring boot应用测试框架介绍
一.spring boot应用测试存在的问题 官方提供的测试框架spring-boot-test-starter,虽然提供了很多功能(junit.spring test.assertj.hamcres ...
随机推荐
- rabbitmq系列四 之路由
1.路由 在上一个的教程中,我们构建了一个简单的日志记录系统.我们能够向许多接收者广播日志消息. 在本次教程中,我们向该系统添加一些特性,比如,我只需要严重错误(erroe级别)的部分日志打印到磁盘文 ...
- 搭建互联网架构学习--004--centos安装Mysql
Mysql安装 1. yum安装mysql yum -y install mysql-server 2. 启动mysql服务 启动mysql:service mysqld start 查看mysql的 ...
- ASP.NET 负载均衡 StateServer Session共享问题(经验记录)
(源地址:http://www.cnblogs.com/ryhan/p/3748976.html) 最近在改造公司的一个系统 支持F5硬件负载,由于系统后面还跟了个异步工具,需要将Admin上传的文件 ...
- 【树】Serialize and Deserialize Binary Tree
题目: Serialization is the process of converting a data structure or object into a sequence of bits so ...
- hostonly、桥接和NAT的联网方式
不多说,直接上干货! 通信设置: 1) hostonly,换句话就是,Windows和Linux在不插网线情况下,也是可以进行通信. 这样设置的好处,有时候,万一比如在农村,没网络.那么,这是最佳方 ...
- 带你了解数据库中事务的ACID特性
前言 前面我们介绍过数据库中 带你了解数据库中JOIN的用法 与 带你了解数据库中group by的用法的相关用法.本章节主要来介绍下数据库中一个非常重要的知识点事务,也是我们项目中或面试中经常会遇到 ...
- Java 并行编程!
多核处理器现在已广泛应用于服务器.台式机和便携机硬件.它们还扩展到到更小的设备,如智能电话和平板电脑.由于进程的线程可以在多个内核上并行执行,因此多核处理器为并发编程打开了一扇扇新的大门.为实现应用程 ...
- SSL虚拟主机安全方案
SSL虚拟主机安全方案 随着虚拟主机技术的发展,功能越来越丰富,已经不仅仅只是满足个人网站的需要,越来越多的小型电子商务网站也采用了虚拟主机来建站,如何为这些商户提供经济.方便的SSL解决方案,成为虚 ...
- QlikView sheet权限
最近遇到了个新问题,需要针对不同的sheet设置不同的权限,具体是用户登录不同账户,可以看到统一文档的不同sheet 对于Qlikview权限设置就不做描述,下面直接进行sheet操作 第一步,打开脚 ...
- Unity3d嵌入web网页
应用场景 程序中的界面风格 UI内容等相关内容需要很容易方便的跟新替换,不使用unity传统的热加载方式,也不想使用和H5等做混合APP的时候, 就用嵌入web来实现. 假如我想替换某个背景图,一般来 ...