1

我想多次运行测试。例如,假设我有一个这样的测试类:-

RunWith(RobolectricTestRunner.class)
public class Common {
     int n = 0;
     @Test
     public void shouldRun() {
          System.out.println(n++);
     ...
     }
}

现在,我怎样才能继续重复测试直到满足条件,比如假设如果 n = 10 然后停止。

我尝试了本博客中描述的一种方法,并创建了一个扩展 RobolectricTestRunner 的自定义测试运行器,并编写了这样的测试类:-

@RunWith(ExtendedRobolectricTestRunner.class)
public abstract class Common  {    

    @Retention(RetentionPolicy.RUNTIME)  
    @Target({ElementType.METHOD})  
    public @interface Repeat {  
          int value();  
    }  

    int n = 0;

    @Test
    @Repeat(10)     
    public void shouldRunCase1Port() {      
        System.out.println(n++);
}

但没有成功。有人可以建议吗?

4

0 回答 0