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 系列: ...
随机推荐
- 解决mysql导入数据量很大导致失败及查找my.ini 位置(my.ini)在哪
数据库数据量很大的数据库导入到本地时,会等很久,然而等很久之后还是显示失败: 这是就要看看自己本地的没mysql是否设置了超时等待,如果报相关time_out这些,可以把mysql.ini尾部添加ma ...
- linux 文件管理命令
一,文件查看more,less,head,tail,cat,tac 分屏查看文件内容 more:和man用法一样,但翻屏到尾部自动推出. less:和man用法一样. head:查看文件的前n行.n默 ...
- Newifi-mini OpenWrt 下 EAP-PEAP,EAP-TLS 企业级无线认证及 FreeRadius3
Newifi-mini OpenWrt 下 EAP-PEAP,EAP-TLS 企业级无线认证及 FreeRadius3 转载注明来源: 本文链接 来自osnosn的博客,写于 2019-07-15. ...
- 备份下ESP8266的AT指令集手册和用例手册中文版,准备为V7做几个ESP8266的例子
指令集手册:https://files.cnblogs.com/files/armfly/4a-esp8266_at_instruction_set_cn.rar 用例手册: https://file ...
- Leetcode题解 - 树、DFS部分简单题目代码+思路(700、671、653、965、547、473、46)
700. 二叉搜索树中的搜索 - 树 给定二叉搜索树(BST)的根节点和一个值. 你需要在BST中找到节点值等于给定值的节点. 返回以该节点为根的子树. 如果节点不存在,则返回 NULL. 思路: 二 ...
- C# transfer local file to remote server based on File.Copy
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; usin ...
- 由“RangeError: Invalid status code: 0”错误所引发的思考
最近发现一个基于Node.js平台上的Express框架运行的Web网站经常报这样一个错误: RangeError: Invalid status code: 网站的源码中有专门针对错误处理的中间件, ...
- C#&.Net干货分享-构造QRCoderHelper生成二维码图片
不想说废话,直接源码拿去用... /// <summary> /// 二维码管理 /// </summary> public class QRCoderHel ...
- InnoDB Architecture (InnoDB In-Memory Structures 转载)
转载.节选于 https://dev.mysql.com/doc/refman/8.0/en/innodb-in-memory-structures.html InnoDB Architecture ...
- 并发编程~~~协程~~~greenlet模块, gevent模块
一 协程 1. 协程: 单线程下的并发,又称微线程,纤程.协程是一种用户态的轻量级线程,即协程是由用户程序自己控制调度的. 并发真正的核心: 切换并且保持状态. 开启协程并发的执行,自己的程序把控着C ...