执行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. day01-day02 初识java、注释、变量、变量命名、基本数据类型

    1. 初识java 1) 什么是java java是一门高级的计算机编程语言 2) JDK的安装 2.1) 下载2.2) 安装2.3) 验证 3) 环境变量的配置 3.1) 打开环境变量3.2) 配置 ...

  2. uiautomatorviewer提示Unable to connect to adb. Check if adb is installed correctly解决方法

    转自:https://www.jianshu.com/p/c8581a70d1bc 解决方案: 1.打开  "E:\android-sdk_r24.4.1-windows\android-s ...

  3. Java 包(package)的概念及实例

    包的作用 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2.如同文件夹一样,包也采用了树形目录的存储方式.同一个包中的类名字是不同的,不同的包中的类的名字是可以相同的,当同时调 ...

  4. Appium 使用笔记

    零.背景 公司最近有个爬虫的项目,先拿小红书下手,但是小红书很多内容 web 端没有,只能用 app 爬,于是了解到 Appium 这个强大的框架,即可以做自动化测试,也可以用来当自动化爬虫. 本文的 ...

  5. Excel映射到实体-easyexcel工具

    来源 项目需要把Excel进行解析,并映射到对象属性,实现类似Mybatis的ORM的效果.使用的方式是自定义注解+POI,这种方式代码复杂而且不易于维护. easyexcel是阿里巴巴开源的一个框架 ...

  6. TortoiseGit 保存账号密码

    TortoiseGit下载网址:http://download.tortoisegit.org/tgit/ 修改.gitconfig .gitconfig 用于记录git配置信息 路径:系统盘:\Us ...

  7. Python高级特性——迭代(Iteration)

    1.给定一个集合list或者tuple,可以通过for …… in ……的语法来实现循环遍历,这个循环我们就叫做迭代 迭代list: >>> m = ['haha','hehe',' ...

  8. GetWindowLong() 函数

    Window API函数,可根据nlndex参数的不同获取指定窗口的相关信息,也可用于获取窗口内存中指定偏移的32位度整型值.该值大小在注册窗口类时设定, 函数原型:Long GetWindowLon ...

  9. My Home Page

    Recently I use github student pack to build my personal home page.

  10. CVE-2019-0708漏洞复现

    前言: 该漏洞前段时间已经热闹了好一阵子了,HW期间更是使用此漏洞来进行钓鱼等一系列活动,可为大家也是对此漏洞的关心程度,接下里就简单的演示下利用此漏洞进行DOS攻击.当然还有RCE的操作,这只演示下 ...