我有一个测试套件类“TestSuite”和 TestA 类
@RunWith(Suite.class)
@Suite.SuiteClasses({TestA.class})
public class TestSuite {
}
============
public class TestA {
@Test
public void test1(){
System.out.println("test1");
}
@Test
public void test2(){
System.out.println("test2");
}
@Test
public void test3(){
System.out.println("test3");
}
}
如何随机运行所有 3 项测试中的 2 项?搜索了一下,看起来我需要创建一个自定义跑步者。有这方面的例子吗?谢谢!
您需要使对象静态,然后在显示导入并让您的测试编号在此处运行的位置替换它并调用您的对象。
for(int i = 0; i < 2; i++) {
//this switch makes checks for a random number between 1 and 3
switch((int)Math.floor(Math.random()*(3-1+1)+1)) {
case 1:
// import and have test 1 run here
break;
case 2:
// import and have test 2 run here
break;
case 3:
// import and have test 3 run here
break;
}
}