刚开始的时候,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的更多相关文章

  1. Execution Order of Event Functions

    In Unity scripting, there are a number of event functions that get executed in a predetermined order ...

  2. unity 脚本执行顺序设置 Script Execution Order Settings

     通过Edit->Project Settings->Script Execution Order打开MonoManager面板  或者选择任意脚本在Inspector视图中点击Execu ...

  3. Execution Order for the ApiController

    Execution Order for the ApiController Assuming the request goes into the ApiController scope, the op ...

  4. Unity3D Script Execution Order ——Question

    我 知道 Monobehaviour 上的 那些 event functions 是 在主线程 中 按 顺序调用的.这点从Manual/ExecutionOrder.html 上的 一张图就可以看出来 ...

  5. Execution Order In a Test Plan

    1.Config Element 2.Pre  Processors 3.Timer 4.Sampler 5.Post Processors 6.Assertions 7.Listener

  6. 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 ...

  7. 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 ...

  8. Unity性能优化(2)-官方教程Diagnosing performance problems using the Profiler window翻译

    本文是Unity官方教程,性能优化系列的第二篇<Diagnosing performance problems using the Profiler window>的简单翻译. 相关文章: ...

  9. Unity中脚本的执行顺序总结(@WhiteTaken)

    (Editor)以上是Unity官方文档中的截图,脚本在被挂载到物体上,会启用Editor的方法Reset. (Initialization)当执行脚本开始,初始化的过程中,依次执行的是Awake-& ...

随机推荐

  1. Python操作MySQL -即pymysql/SQLAlchemy用法

    本节介绍Python对于MySQL的一些操作用法 模块1:pymysql(等同于MySQLdb) 说明:pymysql与MySQLdb模块的使用基本相同,学会pymysql,使用MySQLdb也就不是 ...

  2. C#畅谈“网络电视”

    C#畅谈“网络电视” 以上是大家比较喜欢的网络电视软件,例如:PPTV,BOX央视影音,PPS等. 今天我就和大家来聊一下简单的“网络电视”.虽然和上边的软件没发比,但是正在向着这个目标努力中…… 一 ...

  3. c# json数据解析——将字符串json格式数据转换成对象

    网络中数据传输经常是xml或者json,现在做的一个项目之前调其他系统接口都是返回的xml格式,刚刚遇到一个返回json格式数据的接口,通过例子由易到难总结一下处理过程,希望能帮到和我一样开始不会的朋 ...

  4. Linux svn直接删除版本库文件

    业务目录:/home/web/oa.youxi.com/htdocs/materialsvn地址:svn://192.168.13.61:/oa.youxi.com/htdocs/material m ...

  5. JavaScript 字符串

    字符串属性 属性 描述 constructor 返回创建字符串属性属性的函数 length 返回字符串的长度 prototype 允许您向对象添加属性和方法 字符串方法 Method 描述 charA ...

  6. When Colon Scripting is comming

    当冒号脚本来临-- 前一篇<JSON带来编程界怎样的描述>,已经展开了一种脚本设计概念,以此诞生的脚本语言待定义的语法不多.但总归需要经历各种语言描述能力对比来归纳最终友好特性的. 冒号已 ...

  7. 试用ubuntu-12.04.3-desktop-amd64(二)

    首先说明,采用主机+虚拟机+ubuntu的形式,更具体的则为Win7-64bit + VMWare + ubuntu-12.04.3-desktop-amd64 进入ubuntu后首先考虑到的就是怎么 ...

  8. ViewData与ViewBag比较

    在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从 ...

  9. js与jquery获取父元素,删除子元素的不同方法

    var obj=document.getElementById("id");得到的是dom对象,对该对象进行操作的时候使用js方法 var obj=$("#id" ...

  10. python日期时间处理

    time模块 #-*- coding: utf-8 -*- """ #获取当前时间的时间戳(单位秒) time.time() #推迟指定秒数后再运行 time.sleep ...