SpringBoot单元测试中的测试方法执行顺序
2018-01-25 08:21
211 查看
一、忽略方法@ignore
二、执行顺序@FixMethodOrder(MethodSorter.JVM)
我们在执行JUnit测试用例时,有时需要按照定义顺序执行单元测试方法,比如如在测试数据库相关的用例时候要按照测试插入、查询、删除的顺序测试。
如果不按照这个顺序测试可能会出现问题,
比如删除方法在前面执行,后面的方法就都不能通过测试,因为数据已经被清空了。
而JUnit测试时默认的顺序是随机的。
所以这时就需要有办法要求JUnit在执行测试方法时按照我们指定的顺序来执行。
JUnit是通过@FixMethodOrder注解(annotation)来控制测试方法的执行顺序的。
@FixMethodOrder注解的参数是org.junit.runners.MethodSorters对象,
在枚举类org.junit.runners.MethodSorters中定义了如下三种顺序类型:
MethodSorters.JVM(按照JVM得到的方法顺序,代码中定义的方法顺序)
Leaves the test methods in the order returned by the JVM. Note that the order from the JVM may vary from run to run
MethodSorters.DEFAULT(默认的顺序)
Sorts the test methods in a deterministic, but not predictable, order() (以确定但不可预期的顺序执行)
MethodSorters.NAME_ASCENDING(按方法名字母顺序执行)
Sorts the test methods by the method name, in lexicographic order, with Method.toString() used as a tiebreaker
相关文章推荐
- JUnit4:在测试用例中用FixMethodOrder指定测试方法的执行顺序
- Spring 生命周期 各种初始化方法 执行顺序
- UITableView代理方法执行顺序测试
- Spring AOP 各种拦截方法执行的顺序
- Junit测试方法执行顺序
- junit4的测试方法的执行顺序
- Junit4:测试方法执行顺序
- 控制器一些方法的执行顺序的测试
- [Junit] 测试方法执行顺序
- android不用另建工程进行单元测试及改变测试方法执行顺序
- junit测试方法执行顺序
- SPRING的初始化方法执行先后顺序
- java初始化与构造方法执行顺序测试
- Java 成员变量 静态块 构造块 构造方法执行顺序测试
- [Junit] 测试方法执行顺序
- spring4 执行异步方法
- springboot 启动后执行特定的方法
- Java静态代码块和构造方法执行顺序
- 执行TestNG的测试方法
- 静态块,匿名构造方法,构造方法执行顺序