Spring 整合 Junit4 进行单元测试
1. pom.xml 引入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.10.RELEASE</version>
<scope>test</scope>
</dependency>
2.编写测试用例:
@RunWith(SpringJUnit4ClassRunner.class) 注解让测试运行于Spring测试环境。
@ContextConfiguration注解加载的是Spring的配置文件。
@Test 注解放在需要测试执行的方法上。
package com.phpdragon; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /**
* Created by phpdragon on 2017/4/20.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/META-INF/spring/dubbo-provider.xml")
public class AtresiaTest { @Test
public void test0() {
System.out.println("test0");
} @Test
public void test1() {
class TestObject implements Runnable {
public void run(){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} long timeTasks = 0;
AtresiaDemo demo = new AtresiaDemo();
try {
timeTasks = demo.timeTasks(4,new TestObject());
} catch (InterruptedException e) {
e.printStackTrace();
} System.out.println("timeTasks :"+ timeTasks);
}
}
3.右键执行:

PS:
http://www.cnblogs.com/wangtj-19/p/5821725.html
https://blog.csdn.net/xxj_jing/article/details/71455522
https://www.cnblogs.com/yanduanduan/p/6548041.html
https://www.cnblogs.com/zxf330301/p/5995126.html
https://blog.csdn.net/dyr_1203/article/details/82965552
https://blog.csdn.net/xiaobing_122613/article/details/80313338
https://blog.csdn.net/qq_32786873/article/details/56480880
https://www.jb51.net/article/134052.htm
https://www.cnblogs.com/aotemanzhifu/p/9192442.html
https://www.cnblogs.com/ggr0305/p/6523574.html
Spring 整合 Junit4 进行单元测试的更多相关文章
- Spring整合Junit4进行单元测试
一. 添加依赖包(maven) <dependency> <groupId>junit</groupId> <artifactId>junit</ ...
- springMVC整合Junit4进行单元测试
springMVC整合Junit4进行单元测试 标签: springMVC整合Junit4junit单元测试教程springMVC入门教程 spring(10) 版权声明:本文为博主原创文章,未 ...
- Spring整合JUnit4进行AOP单元测试的时候,报:"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3\lib\idea_rt.jar=64
错误代码 "C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size= ...
- Spring整合Junit4
1.加入相应依赖包 junit4-4.7.jar 以及spring相关jar包 2.在测试代码的源码包中如 src/test/java 新建一个抽象类如下 import org.junit.runne ...
- Spring整合JUnit4测试
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:spring/ap ...
- Spring整合Junit进行单元测试
I. 加入依赖包 Spring Test (如spring-test-2.5.4.jar) JUnit 4 Spring 其他相关包 II.新建Junit Test Case III.读取配置文件 @ ...
- Spring整合JUnit4测试使用注解引入多个配置文件
转自:https://kanpiaoxue.iteye.com/blog/2151903 我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个.我们在类的注释上面会这 ...
- Spring整合JUnit4测试时,使用注解引入多个配置文件
转自:https://blog.csdn.net/pwh309315228/article/details/62226372 一般情况下: @ContextConfiguration(Location ...
- Spring的AOP开发入门,Spring整合Junit单元测试(基于ASpectJ的XML方式)
参考自 https://www.cnblogs.com/ltfxy/p/9882430.html 创建web项目,引入jar包 除了基本的6个Spring开发的jar包外,还要引入aop开发相关的四个 ...
随机推荐
- windows 下重置 mysql 的 root 密码
今天发现 WordPress 连接不上数据库,登录 window server 服务器查看,所有服务均运行正常. 使用 root 账号登录 mysql 数据库,结果提示密码不匹配.我突然意识到,服务器 ...
- win2008R2管理员密码修改文档
场景:忘记了win2008R2服务器的管理员密码.解决办法:1. 制作一个U盘启动盘:2. 系统通过U盘启动进入WINpe系统3. 在知道Win2008安装位置的情况下:查找C:\windows\sy ...
- Mac如何找到从AppStore下载的正版Xcode安装包、以及Xcode清理缓存
前言:本文介绍在Mac下如何找到AppStore下载的安装包路径,以及如何提取出来供以后使用,希望对大家有所帮助(前提:想要提取某个安装包,前提是你正在从AppStore安装这个程序.比如你想提取im ...
- android:ListView bbs Demo
我们制 作的 message_left.9.png 可以作为收到消息的背景图,那么毫无疑问你还需要再制作一张 message_right.9.png 作为发出消息的背景图. 图片都提供好了之后就可以开 ...
- crucible 的 破解
crucible这个东西用了很久,但是从来都没有想过去破解它,毕竟在公司是不能使用破解 软件的.于是再家里面玩一下而已.下载地址 运行crucible_keygen 如图: 点击 patch 将选择安 ...
- oracle本地编译问题
oracle10.2: --将过程重新编译为本地编译方式,提示有编译错误,经查提示未设置plsql_native_library_dir 参数 SQL> alter procedure p_xx ...
- 解决node使用中8080端口被占用
1.首先按快捷键windows+R,在运行框里输入cmd,如图所示,进入黑色界面后,输入netstat -ano,查看端口. 2.找到8080端口,查看正在运行程序的pid,如图所示. 3.回到桌面, ...
- 每日英语:Upgrade Your Life: How to speed up your PC (or Mac)
Is your desktop or laptop computer starting to feel a little poky? Even after just a few months of u ...
- 【IOS】java 与oc之间的比较
Cocoa是什么,Cocoa是使用OC语言编写的工具包,里面有大量的类库.结构体,其实就相当于java中的标准API.C++中的标准库.OC中没有命名空间的概念,所以使用加前缀来防止命名冲突,因此你会 ...
- Adam算法
结合了Momentum 和RMSprop算法的优点