使用JUnit 5并行执行测试用例

dea*_*mon 3 java junit junit5

是否可以与JUnit 5并行执行测试用例?

我正在寻找类似的东西threadPoolSize,并invocationCountTestNG的

@Test(threadPoolSize = 3, invocationCount = 10,  timeOut = 10000)
Run Code Online (Sandbox Code Playgroud)

Mr.*_*tle 5

您可以使用JUnit 5.3编写并行测试。 https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution

@Execution(ExecutionMode.CONCURRENT)
class MyTest {

    @Test
    void test1() throws InterruptedException {
        Thread.sleep(1000);
        System.out.println("Test1 " + Thread.currentThread().getName());
    }

    @Test
    void test2() throws InterruptedException {
        Thread.sleep(1000);
        System.out.println("Test 2! " + Thread.currentThread().getName());
    }
}

// should run simultaneously 
Run Code Online (Sandbox Code Playgroud)

请记住将添加junit.jupiter.execution.parallel.enabled=true到您的JUnit配置

https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params

如果需要,请将其添加到您的JUnit配置中fixed thread pool

junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4
Run Code Online (Sandbox Code Playgroud)