Verisoft Wiki

Using the @RetryingTest Annotation from the org.junit-pioneer Library

Instead of using the standard @Test annotation, you can use the @RetryingTest annotation from the org.junit-pioneer library.
This annotation is intended to rerun a test multiple times in case it fails, up to the maximum number of attempts defined.

Example:

@RetryingTest(maxAttempts = 3)

In this example, the test will run up to three times

Example Test:

private static int runCount = 0;

@RetryingTest(maxAttempts = 3)
void succeedsOnSecondAttempt() {
    runCount++;
    System.out.println("Running attempt #" + runCount);
    if (runCount < 2) {
        throw new RuntimeException("Failing on first attempt");
    }
    System.out.println("Success on attempt #" + runCount);
}

In this example, the test will run up to three times. The test fails on the first attempt and succeeds on the second, so it does not try a third time because it succeeded. If it had failed on both the second and third attempts, the test would have ultimately failed.


Display in Extent Report:

Display in Report Portal: