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 系列: ...
随机推荐
- pycharm安装第三方包问题解决
pycharm安装第三方包问题解决 pycharm是一个基于python的非常好用的集成开发环境,而python有许多非常不错的开源第三方库,这就需要将一些这样的第三方库导入到我们的项目中去了.然而, ...
- SpringCloud之Feign 负载均衡请求超时时间
版本声明: SpringCloud:Greenwich.SR4 SpringBoot:2.1.9.RELEASE Feign调用服务的默认时长是1秒钟,也就是如果超过1秒没连接上或者超过1秒没响应,那 ...
- 如何修改CAD字体颜色?试试这种方法
CAD中编辑图纸的时候,使用的CAD制图软件来进行绘制,图纸中的CAD字体颜色都是默认的颜色,这样不方便进行查看.这个时候就需要修改CAD字体颜色了,那么如何修改CAD字体颜色呢?具体要怎么来进行操作 ...
- Axure导出的原型无法在谷歌浏览器浏览
1.下载crx后缀的文件. 2.修改crx后缀名为rar的压缩文件 3.解压刚才的rar文件 4.打开谷歌浏览器右上角的三个点 更多工具==>扩展程序 选择刚才的解压文件夹. 上面的图表示安装成 ...
- ES6- Class类的使用,声明,继承
声明一个类 //class 类 class Coder{ // 类中都是方法 函数 //val是name方法的参数 name(val){ console.log(val) //类 return val ...
- Android Studio 3.0+ Record Espresso Test 自动化测试
准备工作 1.将android studio 版本升级到3.0+2.百度下载夜神模拟器 夜神模拟器的基本设置 PS:以上就是夜神模拟器的基本设置 Android Studio 连接夜神模拟器 //夜神 ...
- 【tf.keras】TensorFlow 1.x 到 2.0 的 API 变化
TensorFlow 2.0 版本将 keras 作为高级 API,对于 keras boy/girl 来说,这就很友好了.tf.keras 从 1.x 版本迁移到 2.0 版本,需要修改几个地方. ...
- 08-Django 模板
需要教程的请关注个人微信公众号 模板:产生html,用于控制页面的展示,模板不仅仅是一个html文件,它包含两部分内容: 静态内容:css,js,image 动态内容:用模板语言语言动态的产生一些网页 ...
- TypeScript初体验
第一次运行TypeScript 1.创建文件夹并初始化项目 mkdir ts-demo cd ts-demo npm init -y 2.安装typescript与ts-node # 局部安装 npm ...
- fiddler抓包的一些基本知识整理
fiddler常用命令:selelct xx: 高亮显示所有的text,js,image等响应类型?xxx:匹配所有url.protocol.host中包含xxx的会话=404:选择响应状态码为404 ...