执行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的更多相关文章

  1. 能力 or say 职业 规划

    2019.5.8 黑盒测试,白盒测试,接口测试,自动化测试,性能测试..  往测试工程师发展,再是测试开发,高级测试开发..  要是真的喜欢前端,可以再转吧.前端后端应该要清楚它们的区别 前端:广度, ...

  2. 记一个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 ...

  3. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  4. AndroidStudio — Error:Failed to resolve: junit:junit:4.12错误解决

    原博客:http://blog.csdn.net/u013443865/article/details/50243193 最近使用AndroidStudio出现以下问题: 解决:打开app下的buil ...

  5. 「译」JUnit 5 系列:环境搭建

    原文地址:http://blog.codefx.org/libraries/junit-5-setup/ 原文日期:15, Feb, 2016 译文首发:Linesh 的博客:环境搭建 我的 Gith ...

  6. [深入JUnit] 测试运行的入口

    阅读前提 了解JUnit 对JUnit的内部实现有兴趣 不妨看看[深入JUnit] @Before, @After, @Test的秘密] 代码版本: junit 4.12代码搜索工具: http:// ...

  7. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  8. 「译」JUnit 5 系列:架构体系

    原文地址:http://blog.codefx.org/design/architecture/junit-5-architecture/ 原文日期:29, Mar, 2016 译文首发:Linesh ...

  9. 「译」JUnit 5 系列:基础入门

    原文地址:http://blog.codefx.org/libraries/junit-5-basics/ 原文日期:25, Feb, 2016 译文首发:Linesh 的博客:JUnit 5 系列: ...

随机推荐

  1. PromiseKit基本使用及源码解析

    Promise处理一系列异步操作的应用框架,能够保证顺序执行一系列异步操作,当出错时可以通过catch捕获错误进行处理.Promise框架也是很好的诠释了swift的面相协议编程以及函数式编程 两种类 ...

  2. 如何快速将百度大脑AI技术内置智能小程序中

    实现效果: 该AI智能小程序目前集成了百度AI开放平台数十个AI服务产品功能,包括人脸识别.文字识别.表格识别.红酒识别.货币识别.地标识别.手势识别.商标识别.果蔬识别.菜品识别等图片识别功能,以及 ...

  3. 计算机组成原理——输入输出(I/O)系统考研题

    (一)   I/O系统基本概念 (二)   外部设备 1.     输入设备:键盘.鼠标2.     输出设备:显示器.打印机3.     外存储器:硬盘存储器.磁盘阵列.光盘存储器 (三)   I/ ...

  4. 集合系列 Map(十五):TreeMap

    TreeMap 是 Map 集合的有序实现,其底层是基于红黑树的实现,能够早 log(n) 时间内完成 get.put 和 remove 操作. public class TreeMap<K,V ...

  5. JS基础语法---String(字符串的案例)

    练习1: var str = "我的宝宝最可爱,声音嗲嗲的"; var key = "可爱"; //先获取要截取的字符串的索引位置 var index = st ...

  6. 短信相关的AT指令以及信令

    本文链接:https://blog.csdn.net/sjz4860402/article/details/78552756 此次的短信AT指令和信令从以下几个方面介绍: 一 . 短信AT指令的格式二 ...

  7. AWS云EC2(RHEL7)添加网络接口与路由调整

    AWS云EC2(RHEL7)添加网络接口与路由调整 Amazon Linux(类似RHEL6,Centos6) 以及 RHEL7 修改MAC地址的说明 RHEL7 Centos7 添加路由 解决RHE ...

  8. pgwSlideshow.js

    <!DOCTYPE html> <html> <head id="Head"> <meta http-equiv="Conten ...

  9. jQuery - 拦截所有Ajax请求(统一处理超时、返回结果、错误状态码 )

    样例代码: <html> <head> <title>hangge.com</title> <meta charset="utf-8&q ...

  10. 寝室远程连接室友mysql数据库

    注意,本方法是适用于同一局域网下的远程连接 注意,本方法是适用于同一局域网下的远程连接 注意,本方法是适用于同一局域网下的远程连接 首先需要修改mysql数据库的相关配置,将user表中的host改为 ...