hikamen
2/25/2018 - 12:57 PM

测试用例中方法的执行顺序

Junit4默认依赖反映API返回的测试方法的顺序来执行,这种方式有点随机,从4.11版本开始,可以指定方法名的升序或者降序执行,例如:

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestMethodOrder {

    @Test
    public void testA() {
        System.out.println("first");
    }
    @Test
    public void testB() {
        System.out.println("second");
    }
    @Test
    public void testC() {
        System.out.println("third");
    }
}