junit默认按方法名的按方法名的hashcode排序
若希望junit执行顺序,可在类名上添加注解:@FixMethodOrder
@FixMethodOrder接受MethodSorters枚举值
MethodSorters的具体枚举值有:
- NAME_ASCENDING:按方法名的toString()函数结果排序
- JVM:顺序随机
- DEFAULT:MethodSorters的默认值,junit默认的执行顺序。按方法名的hashcode排序
例如:
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Test {
@Test
public void test01Test() { System.out.println("a"); }
@Test
public void test02Test() { System.out.println("b"); }
@Test
public void test03Test() { System.out.println("c"); }
@Test
public void test04Test() { System.out.println("d"); }
@Test
public void test05Test() { System.out.println("e"); }
@Test
public void test06Test() { System.out.println("f"); }
}