JUnit与MSTest
执行test类的每个方法时,需要做一些初始化。比如初始化applicationcontext。JUnit使用@Before注解。
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class PageProcessorTest {
@Autowired
OrderList0Processor orderList0Processor;
@Autowired
ApplicationContext applicationContext; @Before
public void init(){
System.out.println("this is @Before");
ApplicationContextUtils.setContext(applicationContext);
} @Test
public void spiderT0() { // ApplicationContextUtils.setContext(applicationContext);
orderList0Processor.startSpider(2);
log.info("当前页数:{}", orderList22Processor.getPageSize());
}
}
JUnit与MSTest。
|
Junit |
MSTest -MSTest.TestFramework -MS.VisualStudio.QualityTools.UnitTestFramework |
|
|
注解/Annotation |
特性/Attribute |
|
|
@RunWith |
[TestClass] |
声明在class上。 声明一个class为Test类(java命名规范是在被测试类后加Test) |
|
@BeforeClass |
[ClassInitialize] |
声明在方法上。 在所有Test方法执行前执行。(junit要求方法必须是静态的) |
|
@Before |
[TestInitialize] |
声明在方法上。 在每个Test方法执行前执行。 |
|
@Test |
[TestMethod] |
声明在方法上。 声明方法为Test方法 |
|
@After |
[TestCleanUp] |
声明在方法上。 在每个Test方法运行后被执行一次 |
|
@AfterClass |
[ClassCleanUp] |
声明在方法上。 在所有Test方法运行后执行。(junit要求方法必须是静态的) |
JUnit与MSTest的更多相关文章
- 能力 or say 职业 规划
2019.5.8 黑盒测试,白盒测试,接口测试,自动化测试,性能测试.. 往测试工程师发展,再是测试开发,高级测试开发.. 要是真的喜欢前端,可以再转吧.前端后端应该要清楚它们的区别 前端:广度, ...
- 记一个mvn奇怪错误: Archive for required library: 'D:/mvn/repos/junit/junit/3.8.1/junit-3.8.1.jar' in project 'xxx' cannot be read or is not a valid ZIP file
我的maven 项目有一个红色感叹号, 而且Problems 存在 errors : Description Resource Path Location Type Archive for requi ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- AndroidStudio — Error:Failed to resolve: junit:junit:4.12错误解决
原博客:http://blog.csdn.net/u013443865/article/details/50243193 最近使用AndroidStudio出现以下问题: 解决:打开app下的buil ...
- 「译」JUnit 5 系列:环境搭建
原文地址:http://blog.codefx.org/libraries/junit-5-setup/ 原文日期:15, Feb, 2016 译文首发:Linesh 的博客:环境搭建 我的 Gith ...
- [深入JUnit] 测试运行的入口
阅读前提 了解JUnit 对JUnit的内部实现有兴趣 不妨看看[深入JUnit] @Before, @After, @Test的秘密] 代码版本: junit 4.12代码搜索工具: http:// ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- 「译」JUnit 5 系列:架构体系
原文地址:http://blog.codefx.org/design/architecture/junit-5-architecture/ 原文日期:29, Mar, 2016 译文首发:Linesh ...
- 「译」JUnit 5 系列:基础入门
原文地址:http://blog.codefx.org/libraries/junit-5-basics/ 原文日期:25, Feb, 2016 译文首发:Linesh 的博客:JUnit 5 系列: ...
随机推荐
- sonar安装和使用
安装 1. 从官网下载,https://www.sonarqube.org/downloads/ 2. 下载之前要看好要求,我安装的是7.6的版本,要求是jdk1.8,mysql 5.6 到8 ,我使 ...
- linux中关于权限的一些事
权限这个东西对于初学者来说可能会有点陌生,不过不要紧,看完下面的讲解应该会对你有一定的帮助 权限rwx rwxrwxrwx u g o a r:可读 4 w: ...
- linux中批量添加文件前缀的操作
需要在文件夹内所有txt文件的文件名前面添加"gt_"; 就是由原来的文件“xxx.txt”变成“gt_xxx.txt”: 网上搜来的脚本如下: for i in `ls`; do ...
- Python 的 Geth 封装库 PyGeth
PyGeth 是一个 Python 封装库,用来作为子进程运行 geth. 系统依赖 该库需要 geth 可执行文件. 安装 pip install py-geth 快速启动 运行连接到 mainne ...
- 事隔五年之后,开启第2版DSP数字信号处理和CMSIS-NN神经网络教程,同步开启三代示波器,前15章发布(2019-11-04)
说明:1.第1版DSP教程发布于2014年末,纪念下:https://www.cnblogs.com/armfly/p/11274826.html2.这几年在信号处理的应用上积累了一些经验,也发现了很 ...
- webpack动态加载打包chunk命名
最近,遇到复杂h5页面开发,为了优化H5首屏加载速度,想到使用按需加载的方式,减少首次加载的JavaScript文件体积,于是将处理过程在这里记录一下,涉及到的主要是以下三点: 使用Webpack如何 ...
- MySql报错(持续更新)
目录 MySql报错 1. 重复键报错1062- duplicate entry '0' for key 'xxx' 1.1 报错场景 1.2 报错原因 1.3 解决方法 1.4 具体举例 2. VS ...
- Toggle the WinForms Ribbon Interface 切换 WinForms 功能区界面
In this lesson, you will learn how to enable/disable the Ribbon User Interface in your application. ...
- 如何使用CAD删除命令?怎么删除图纸中线段
大家经常使用CAD制图软件来绘制图纸,那在绘制图纸的过程中有时候会出现一些问题,就是图纸中不小心多绘制了一个线段,那要怎么办呢?如何使用CAD删除命令?怎么删除图纸中线段呢?那下面小编就来教教大家具体 ...
- Axure制作dialog效果的动作步骤
1.在Axure中添加一个弹框按钮 2.将动态面版拖动到界面中 3.双击动态面版,双击state 4.拖入一块图片占位符进来 5.设置图片 6.回到上一个界面设置动态面版的大小,使其 ...