@RunWith的使用
文章目录
- @RunWith作用
- @RunWith(SpringJunit4ClassRunner.class) 使用说明
- 测试@ActiveProfiles("dev")
@RunWith作用
@RunWith 就是一个运行器
@RunWith(JUnit4.class) 就是指用JUnit4来运行
@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
@RunWith(Suite.class) 的话就是一套测试集合,
@ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件
单个文件
@ContextConfiguration(Locations=“classpath:applicationContext.xml”)
@ContextConfiguration(classes = SimpleConfiguration.class)
多个文件时,可用{}
@ContextConfiguration(locations = { “classpath:spring1.xml”, “classpath:spring2.xml” })
@RunWith(SpringJunit4ClassRunner.class) 使用说明
转载:https://blog.csdn.net/u013803262/article/details/52253825
今天在看Spring的Demo的时候,看到了如此单元测试的写法
如下:
@RunWIth(SpringJunit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"}
public class MyTest
{@Testpublic void hehe(){//.......}
}
这种写法是为了让测试在Spring容器环境下执行。
Spring的容器环境是啥呢?
比如常见的 Service Dao Action , 这些个东西,都在Spring容器里,junit需要将他们拿到,并且使用来测试。
好,笔者写一个十分简单的demo让大家有个体会!
显示demo的项目结构:
要写的东西就两个 applicationContext.xml 和MyTest.java
applicationContext.xml 中仅仅只定义了一个Date对象。
接下来是MyTest.java的内容:
最后只需要运行就可以了。
最后如图所示,成功拿到了Spring容器里的Date对象。
诸如哪些 Action Service Dao ServiceImpl DaoImpl都是一个道理,可以通过这种方式拿到,然后进行单元测试。。。
测试@ActiveProfiles(“dev”)
package com.ssm.chapter10.test;
import javax.sql.DataSource;
/*******imports******/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=ProfileConfig.class)
@ActiveProfiles("dev")
public class ProfileTest{@Autowiredprivate DataSource dataSource;@Testpublic void test(){System.out.println(dataSource.getClass().getName());}
}
@RunWith作用 - weixin_41315469的博客 - CSDN博客
https://blog.csdn.net/weixin_41315469/article/details/79675044
@RunWith(SpringJunit4ClassRunner.class) 使用说明 - 码农在路上 - 博客园
https://www.cnblogs.com/lzmrex/articles/9236977.html
@RunWith的使用相关推荐
- Maven项目中引入spring-test单元测试 @RunWith与@ContextConfigration报错
场景 在SSM项目整合时引入spring-test单元测试时, @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locati ...
- springboot集成测试时@RunWith和@SpringBootTest爆红不能测试
场景:由于程序中从redis中获取到的值不正确,需要一个测试类测试下根据key从redis中获取到的值具体是什么.所以有了下面的代码 import lombok.extern.slf4j.Slf4j; ...
- springboot报错---@RunWith(SpringRunner.class)
@RunWith(SpringRunner.class)因为缺乏pom文件里Junit依赖导致. 解决方法: 在pom.xml里添加以下依赖 <dependency><groupId ...
- 使用RunWith注解改变JUnit的默认执行类,并实现自已的Listener
2019独角兽企业重金招聘Python工程师标准>>> 使用RunWith注解改变JUnit的默认执行类,并实现自已的Listener在平时的单元测试,如果不使用RunWith注解, ...
- @RunWith@ContextConfiguration进行Spring上下文测试报错
最近在进行Spring的回炉学习在通过 @RunWith和@ContextConfiguration 进行Spring上下文进行测试 具体代码如下: @RunWith(SpringRunner.cla ...
- java powermockrunner_java – PowerMock从@RunWith(PowerMockRunner.class)注释中抛出异常
我正在努力让PowerMockito使用我的应用程序.我已将库添加到构建路径中.我有以下测试类: package client.controller; import org.junit.Test; i ...
- @RunWith注解的作用
@RunWith注解的作用 @RunWith就是一个运行器 @RunWith(JUnit4.class)就是指用JUnit4来运行 @RunWith(SpringJUnit4ClassRunner.c ...
- 天呐!惊人的Springboot测试.Springboot测试类之@RunWith注解
Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解 Springboot测试类之@RunWith注解 @runWith注解作用: @RunWith就是一 ...
- @RunWith的作用
@RunWith就是一个运行器 @RunWith(JUnit4.class)就是指用JUnit4来运行 @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Sp ...
最新文章
- [转] Leaving patterns practices
- iOS安全攻防(十七):Fishhook
- 石头扫地机器人加速异响_米家扫地机器人有异响怎么办
- 何亚明:Facebook的工具文化和多媒体QoE
- python的request请求401_Python模拟HTTPS请求返回HTTP 401 unauthorized错误
- 【算法分析与设计】二分查找平均查找长度的求解
- vue下使用axios应用
- MySQL SQL 优化命令行问题 SQL 抓取方式
- 热点热词 新闻热点 最新新闻数据API接口-天狗热点热词开放平台
- html 获取mac地址,Javascript获取Mac地址
- JavaScript文档对象模型DOM节点概述(1)
- SPC-Light显示正常的日期与时间
- snowflake算法
- 论网络工程中,系统开发设计可行性研究及市面产品对比!
- j2ee是什么?(1)
- APP兼容性覆盖测试
- 推荐系统中的常用算法——基于Graph Embedding的GES和EGES
- 数据结构 | 合并两个长度分别为m和n的有序表,最坏情况下需要比较m+n-1次
- 小盒子可以在大盒子里面移动
- MAML 源代码解释说明 (一)
热门文章
- 四巫日来临本周硅铁、铁矿石领跌,铁矿石认沽最高31倍,钢厂利润回升2022.6.17
- Opencv中,imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) 报错:error:!_src.empty() in function ‘cv::cvtColor‘
- 一篇关于校园的爱情故事:伤感
- 计算机毕业设计Python+uniapp学生考勤系统小程序(小程序+源码+LW)
- 攻击者思维 - iOS 摄像头指示灯不亮,就真的没事了吗?
- 治理企业“数据悬河”,阿里云DataWorks全链路数据治理新品发布
- 【Java进阶营】阿里架构师加持,十分钟入门RocketMQ,就是这么简单
- 如何在线制作gif图片?
- Linux(Centos6.5)下安装Vertica9.2.1数据库教程
- 原来我们都让历史书骗了- -#!~