JUnit 5 has added support for running a test a specified number of times, an essential when you work with tests that are flaky in nature, e.g., those with a stochastic component.
Flaky tests are those that exhibit both a passing and failing results despite zero changes to the code or test.
To run a test for a specific number of times, mark it with the @RepeatedTest
annotation as shown below.
@RepeatedTest(10)
void runMeMultipleTimes() {
assertTrue(true);
}
You can customize the name of the test using a predefined set of placeholders.
@RepeatedTest(value = 10, name = "runMe {currentRepetition}/{totalRepetitions}")
void runMeMultipleTimesCustomName() {
assertTrue(true);
}