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-& ...
随机推荐
- Volley框架使用(POST)
需要在MyApplication(继承Application)中配置; public static RequestQueue requestQueue; @Override public void o ...
- 为什么z-index不起作用
感觉很简单的东西 在用的时候 可能会遇到这样活那样的问题 这就是要注意细节:参考地址:http://www.ourjour.com/136/ 设置z-index 不起作用,可能是这三个原因: 1.父标 ...
- 一个tomcat部署俩个java web项目
2.发布的时候可以发布成war包,用项目名称右键export,选择项目名称,还有发布的路径,即tomcat下的路径,参考http://zhidao.baidu.com/link?url=imOu0Uu ...
- CentOS 6.5下安装MySql 5.7
不管您按下面的方法安装成功否,请留个言,把您遇到的问题写上共勉! 包下载http://url.cn/WrNg5S 环境: 1).软硬件:E6420双核CPU,8G内存,1T硬盘 2).虚拟机下 Cen ...
- ORACLE数据库多表关联查询效率问题解决方案
最近在做项目中遇到多表关联查询排序的效率问题(5张以上40W+数据的表),查询一次大概要20多秒,经过一番苦思冥想,处理方案如下: 1.软件设计初期,需要一对一关联的表应该设计在一张大表里,这样虽然字 ...
- Extjs之遍历Store内的数据
Store作为数据的载体,通过下面的方法可以获得Store内的数据; Ext.define('haomlGeimjTongjGrid_store_data', { extend: 'Ext.data. ...
- gdb调试memcached
1.memcached安装前,要安装libevent 2.memcached在configure中 加上 CPPFLAGS='-ggdb3'选项 例如 本机 ./configure -prefix ...
- HDU 1312:Red and Black(DFS搜索)
HDU 1312:Red and Black Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- Oracle中批量插入
为了防止OracleConnection的重复打开和关闭,使用begin end:将sql语句包在里面,然后一次性执行提高插入的效率. 下面代码中要插入的数据在list集合中,如果list集合的cou ...
- C#复习,输入学生信息排列成绩
C#复习:在控制台程序中使用结构体.集合,完成下列要求项目要求:一.连续输入5个学生的信息,每个学生都有以下4个内容:1.序号 - 根据输入的顺序自动生成,不需要手动填写,如输入第一个学生的序号是1, ...