执行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. 安卓JNI精细化讲解,让你彻底了解JNI(二):用法解析

    目录 用法解析 ├── 1.JNI函数 │ ├── 1.1.extern "C" │ ├── 1.2.JNIEXPORT.JNICALL │ ├── 1.3.函数名 │ ├── 1 ...

  2. CGI environment variables

  3. C# 多线程总结 异常处理 线程取消 锁(lock)

    那么什么时候能用多线程? 任务能并发的时候 多线程能干嘛?提升速度/优化用户体验 网站首页:A数据库 B接口 C分布式服务 D搜索引擎,适合多线程并发,都完成后才能返回给用户,需要等待WaitAll列 ...

  4. Java生鲜电商平台-高可用微服务系统如何设计?

    Java生鲜电商平台-高可用微服务系统如何设计? 说明:Java生鲜电商平台高可用架构往往有以下的要求: 高可用.这类的系统往往需要保持一定的 SLA,7*24 时不间断运行不代表完全不挂,而是有一定 ...

  5. js-05-对象(object)

    一.访问对象属性的两种方法 a:objectName.PropertyName     对象名.属性名 b:objectName["PropertyName"]     对象名[“ ...

  6. C lang: Compound literal

    Xx_Introduction C99 stantard. Upate array and struct a compound literal. Literal is date type value. ...

  7. [20191122]oracel SQL parsing function qcplgte.txt

    [20191122]oracel SQL parsing function qcplgte.txt --//昨天看了链接:https://nenadnoveljic.com/blog/memory-l ...

  8. 特殊权限SUID

    特殊权限SUID SUID : 运行某程序时,相应进程的属主是程序文件自身的属主,而不是启动者: chmod u+s File chmod u-s File 如果 FileB本身原来就有执行权限,则S ...

  9. Appium(三):安装appium client、adb命令

    1. 安装appium client appium client是对webdriver原生api的一些扩展和封装.它可以帮助我们更容易的写出用例,写出更好的用例. appium client是配合原生 ...

  10. Ribbon负载均衡及Feign消费者调用服务

    微服务调用Ribbon 简介 前面讲了eureka服务注册与发现,但是结合eureka集群的服务调用没讲. 这里的话 就要用到Ribbon,结合eureka,来实现服务的调用: Ribbon是Netf ...