@RunWith(Parameterized.class) won't work in JUnit 5.
You could use your own launcher. Which might be overkill but it works.
The test class with tests that needs to be repeated:
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@Disabled
public class OrderedExampleTest {
@Test
@Order(1)
public void shouldRunFirst() {
System.out.println("First!! ");
}
@Test
@Order(2)
public void shouldRunSecond() {
System.out.println("Second!!");
}
@Test
@Order(3)
public void shouldRunThird() {
System.out.println("Third!!");
}
}
And then in a separate class a special test method that will re-run this whole class multiple times:
public class ExternalRunnerTest {
@Test
public void shouldRepeatTestClass() {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(
selectPackage("org.igorski.repeated"),
selectClass(OrderedExampleTest.class)
)
.configurationParameter("junit.jupiter.conditions.deactivate", "org.junit.*DisabledCondition")
.build();
Launcher launcher = LauncherFactory.create();
int numberOfRepeats = 5;
for(int i = 0; i < numberOfRepeats; i++) {
launcher.execute(request);
}
}
}
The OrderedExampleTest is disabled. So it should not run on its own when you run all the tests together. But, the special repeat test will ignore the disabling condition and run the test.
In my case this prints:
First!!
Second!!
Third!!
First!!
Second!!
Third!!
First!!
Second!!
Third!!
First!!
Second!!
Third!!
First!!
Second!!
Third!!