Search code examples
junit5retry-logic

[Junit-pioneer]How to add RetryingTest for all test methods?


I'd like to use @RetryingTest(3) for all my test methods, is there a easy way to apply it for all test methods instead of add @RetryingTest(3) for test method one by one? Or if there is a global way to enable retry for all test methods?

Walkthough docs:


Solution

  • No (at least out of the box) since @RetryingTest is a @TestTemplate:

    @TestTemplate is used to signal that the annotated method is a test template method.

    Similar to @Test, it is designed to target only ANNOTATION_TYPE and METHOD. JUnit Jupiter had a similar request back in 2019 and they decided against a class-level @Test annotation:

    There are many ways to declare tests in Jupiter: @Test, @TestFactory, @TestTemplate (@RepeatedTest, @ParameterizedTest) -- we want them to be explicitly visible and not rely on a pattern that matches a method signature.

    See also: https://github.com/junit-pioneer/junit-pioneer/issues/720