如何让junit的测试跑多次

对JUnit4可以使用下面的方法:

@RunWith(Parameterized.class)
public class RunTenTimes {

    @Parameterized.Parameters
    public static Object[][] data() {
        return new Object[10][0]; // repeat count which you want
    }

    @Test
    public void runsTenTimes() {
        System.out.println("run");
    }
}

下图是我执行了十次的结果:
在这里插入图片描述

对JUnit5可以使用下面的方法:

@RepeatedTest(10) // repeat count which you want
public void testMyCode() {
    //your test code goes here
}

https://stackoverflow.com/questions/1492856/easy-way-of-running-the-same-junit-test-over-and-over

猜你喜欢

转载自blog.csdn.net/lantianjialiang/article/details/82811704
今日推荐