Test execution order
刚开始的时候,JUnit并没有规定测试方法的调用执行顺序。方法通过映射的API返回的顺序进行调用。然 而,使用JVM顺序是不明智的,因为Java平台没有规定任何特定的顺序,事实上JDK7或多或少的返回的是随机顺序。大部分写的好的测试代码不会假定一 个顺序,在特定的平台上一个可预言的失败比一个随机的失败更好。
从4.11版本开始,如果想要改变测试执行顺序,只要简单的加一个 @FixMethodOder 注释就可以。
目前比较常见的有三种:
@FixMethodOrder(MethodSorters.DEFAULT):默认顺序。由方法名的哈希码值决定执行顺序。由于哈希码的生成和OS有关,所以不用的OS可能会出现不一样的执行顺序。在某一操作系统上,多次执行的顺序不变。
@FixMethodOrder(MethodSorters.JVM):由JVM来决定执行顺序。当然执行顺序随着每一次的测试可能会有所不用。
@FixMethodOrder(MethodSorters.NAME_ASCENDING):由方法名的字典顺序来决定执行顺序。
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters; //@FixMethodOrder(MethodSorters.DEFAULT)
//@FixMethodOrder(MethodSorters.NAME_ASCENDING)
//@FixMethodOrder(MethodSorters.JVM)
public class TestExecuteOrder { @Test
public void test03Third() {
System.out.println("test03");
} @Test
public void test01First() {
System.out.println("test01");
} @Test
public void test02Second() {
System.out.println("test02");
}
}
执行结果如下
1.什么都不加:
test02
test01
test03
2. @FixMethodOrder(MethodSorters.DEFAULT) :
test02
test01
test03
3. @FixMethodOrder(MethodSorters.NAME_ASCENDING):
test01
test02
test03
4. @FixMethodOrder(MethodSorters.JVM):
test03
test01
test02
或者
test02
test01
test03
Test execution order的更多相关文章
- Execution Order of Event Functions
In Unity scripting, there are a number of event functions that get executed in a predetermined order ...
- unity 脚本执行顺序设置 Script Execution Order Settings
通过Edit->Project Settings->Script Execution Order打开MonoManager面板 或者选择任意脚本在Inspector视图中点击Execu ...
- Execution Order for the ApiController
Execution Order for the ApiController Assuming the request goes into the ApiController scope, the op ...
- Unity3D Script Execution Order ——Question
我 知道 Monobehaviour 上的 那些 event functions 是 在主线程 中 按 顺序调用的.这点从Manual/ExecutionOrder.html 上的 一张图就可以看出来 ...
- Execution Order In a Test Plan
1.Config Element 2.Pre Processors 3.Timer 4.Sampler 5.Post Processors 6.Assertions 7.Listener
- How to define Servlet filter order of execution using annotations
If we define Servlet filters in web.xml, then the order of execution of the filters will be the same ...
- System and method for parallel execution of memory transactions using multiple memory models, including SSO, TSO, PSO and RMO
A data processor supports the use of multiple memory models by computer programs. At a device extern ...
- Unity性能优化(2)-官方教程Diagnosing performance problems using the Profiler window翻译
本文是Unity官方教程,性能优化系列的第二篇<Diagnosing performance problems using the Profiler window>的简单翻译. 相关文章: ...
- Unity中脚本的执行顺序总结(@WhiteTaken)
(Editor)以上是Unity官方文档中的截图,脚本在被挂载到物体上,会启用Editor的方法Reset. (Initialization)当执行脚本开始,初始化的过程中,依次执行的是Awake-& ...
随机推荐
- visual studio中的一些实用的快捷键
重置开发环境:使得开发工具恢复默认状态 方法:工具->导入和导出设置导向->重置所有设置->不保存 显示行号: 方法:工具->选项->所有语言->行号 在编程过程中 ...
- 开始学习编程了…… 2015年九月七日 …… 31岁的Me.
给自己下的命令:做今天开始认认真真地开始学习编程,一年后的今天一定要找到一份编程的工作. 为什么要学编程?:因为不想回以前的圈子,“创业”快三年什么都给“创”没了,咳……,不过呢,倒是领略到编程能带来 ...
- OD: RPC - MS06040 & MS08067
RPC 漏洞简介 Remote Procedure Call,分布式计算中常用到的技术.两台计算机通信过程可以分为两种形式:一种是数据的交换,另一种是进程间通信.RPC 属于进程间通信. RPC 就是 ...
- 在CSS文件中引入其他CSS文件
引入CSS的方法有两种,一种是@import,一种是link 一.@import url('地址');二.<link href="地址" rel="styleshe ...
- c#中去掉字符串空格方法
(1)Trim方法 string tt=" aaa "; tt=tt.Trim() 去字符串首尾空格的函数 tt=tt.TrimEnd() 去掉字符串尾空格 tt= ...
- linux command cp.
Examples cp file1.txt newdir Copies the file1.txt in the current directory to the newdir subdirector ...
- linux术语解析(持续更新)
1.linux内核有个版本,分别是 longterm: 提供长期支持的内核版本 stable: 稳定版本 Beta 测试版
- javascript基础学习(十一)
javascript之BOM 学习要点: BOM介绍 Window对象 一.BOM介绍 浏览器对象模型简称为BOM(Brower Object Model),BOM由很多对象构成,对象与对象之间有着相 ...
- sql -实验二
8. 统计各部门下工资大于2000的雇员的平均工资. select avg(sal)from empwhere sal>2000;
- 文件操作1-php
is_file (PHP 3, PHP 4, PHP 5) is_file -- 判断给定文件名是否为一个正常的文件 说明 bool is_file ( string filename ) 如果文件存 ...