我想选择执行 JUnit 测试的顺序。 我有 4 个类,其中有几个测试方法,我的目标是执行,例如,类 A 的方法 Y,然后是类 B 的方法 X,最后是类 A 的方法 Z。
你能帮忙吗?
最佳答案
从 4.11 版开始,您可以使用注释指定执行顺序并按方法名称排序:
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MyTest {
@Test
public void test1Create() {
System.out.println("first");
}
@Test
public void test2Update() {
System.out.println("second");
}
}
关于java - 选择执行 JUnit 测试的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2669414/