执行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. 解决Android调用相机拍照,要报“打开相机失败”查看debug日志显示“setParameters failed”的问题

    使用CameraLibrary项目,在部分手机或平板上不能正常使用,要报“打开相机失败”查看debug日志显示“setParameters failed”. 找到CameraView.java中的se ...

  2. iOS开发 - 超级签名实现之描述文件

    简介 因为最近企业签掉得太严重了,上头要求实现超级签进行游戏下载.故有了此文章,记录一下过程. 签名原理其实很简单,超级签名的技术就是使用个人开发者账号,将用户的设备当作开发设备进行应用分发.这也导致 ...

  3. CODING 代码多仓库实践

    关于代码的管理问题已经讨论多年,随着企业业务的复杂度提高.软件行业技术栈的选择度变宽泛,现代软件的代码仓库也变得越来越庞大和复杂.一个中型项目,将测试代码.核心业务代码.编译构建.部署打包等基础设施的 ...

  4. (办公)记事本_Linux权限

    参考谷粒学院Linux教程:http://www.gulixueyuan.com/course/300/task/7084/show# linux权限,什么用户可以操作什么. 1.基本权限的作用: 1 ...

  5. VMware_Player_nat网络的端口映射_手工设置

    VMware_Player_nat网络的端口映射_手工设置 转载注明来源: 本文链接 来自osnosn的博客,写于 2019-12-21. vmware nat的配置文件在 C:\ProgramDat ...

  6. MySQL去重保留最大的那条记录(取最新的记录)

    以用户登录日志表为例,取用户最近登录的设备 1 SET NAMES utf8mb4; 2 ; 3 4 -- ---------------------------- 5 -- Table struct ...

  7. python网络编程:UDP方式传输数据

    UDP --- 用户数据报协议(User Datagram Protocol),是一个无连接的简单的面向数据报的运输层协议. UDP不提供可靠性,它只是把应用程序传给IP层的数据报发送出去,但是并不能 ...

  8. java 整合redis缓存 SSM 后台框架 rest接口 shiro druid maven bootstrap html5

    A 调用摄像头拍照,自定义裁剪编辑头像,头像图片色度调节B 集成代码生成器 [正反双向](单表.主表.明细表.树形表,快速开发利器)+快速表单构建器 freemaker模版技术 ,0个代码不用写,生成 ...

  9. 数据库死锁的问题,Deadlock found when trying to get lock; try restarting transaction at Query.formatError

    场景: 应用刚上线排除大批量请求的问题 线上多次出现的Deadlock found when trying to get lock错误 代码: async batchUpdate(skus, { tr ...

  10. partition by 与ROW_NUMBER()函数使用详解

    SQL Server数据库partition by 与ROW_NUMBER()函数使用详解 关于SQL的partition by 字段的一些用法心得 先看例子: if object_id('TESTD ...