-
@Target({METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) @ExtendWith(RetryingTestExtension.class) @TestTemplate public @interface RetryingTest@RetryingTestis a JUnit Jupiter extension that retries a failing test a certain number of times before the test actually shows up as failing.If annotated with
@RetryingTest(n), a test method is executed as long as it keeps failing, but no more thanntimes. That means all actual executions - except possibly the last - have failed. In contrast, all executions - except possibly the last - show up as being ignored/aborted because that is the best way to communicate a problem without breaking the test suite. Only if allnexecutions fail, is the last one marked as such. Each ignored/aborted or failed execution includes the underlying exception.By default the test will be retried on all exceptions except
TestAbortedException(which will abort the test entirely). To only retry on specific exceptions, useonExceptions().@RetryingTesthas a number of limitations:- it can only be applied to methods
- methods annotated with this annotation MUST NOT be annotated with
@Testto avoid multiple executions! - it can't be used with other
TestTemplate-based mechanisms likeorg.junit.jupiter.api.RepeatedTest @RepeatedTestororg.junit.jupiter.params.ParameterizedTest @ParameterizedTest - it can't be used with
org.junit.jupiter.api.DynamicTest @DynamicTest - all retries are run sequentially, even when used with parallel test execution
During parallel test execution, all repetitions of a
RetryingTestare executed sequentially to guarantee thread-safety.For more details and examples, see the documentation on
@RetryingTest.Before version 0.7.0 this annotation was called
@RepeatFailedTest.- Since:
- 0.4
-
-
Field Summary
Fields Modifier and Type Fields Description static java.lang.StringDISPLAY_NAME_PLACEHOLDERPlaceholder for the display name of a@RetryingTest:{displayName}static java.lang.StringINDEX_PLACEHOLDERPlaceholder for the current invocation index of a@RetryingTestmethod (1-based):{index}
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description intmaxAttemptsSpecifies how often the test is executed at most.intminSuccessSpecifies the minimum number of successful executions of the test.java.lang.StringnameThe display name to be used for individual invocations of the parameterized test; never blank or consisting solely of whitespace.java.lang.Class<? extends java.lang.Throwable>[]onExceptionsSpecifies on which exceptions a failed test is retried.intsuspendForMsSpecifies a pause (in milliseconds) between executions.intvalueSpecifies how often the test is executed at most.
-
-
-
Field Detail
-
DISPLAY_NAME_PLACEHOLDER
static final java.lang.String DISPLAY_NAME_PLACEHOLDER
Placeholder for the display name of a@RetryingTest:{displayName}- Since:
- 1.7.0
- See Also:
name()
-
-
-
INDEX_PLACEHOLDER
static final java.lang.String INDEX_PLACEHOLDER
Placeholder for the current invocation index of a@RetryingTestmethod (1-based):{index}- Since:
- 1.7.0
- See Also:
name()
-
-
Element Detail
-
name
java.lang.String name
The display name to be used for individual invocations of the parameterized test; never blank or consisting solely of whitespace.Defaults to [{index}] {arguments}.
Supported placeholders:
-DISPLAY_NAME_PLACEHOLDER-INDEX_PLACEHOLDERYou may use
MessageFormatpatterns to customize formatting.- Since:
- 1.7.0
- See Also:
MessageFormat,ParameterizedTest.name()
- Default:
- "[{index}]"
-
-
-
value
int value
Specifies how often the test is executed at most.Alias for
maxAttempts().- Default:
- 0
-
-
-
maxAttempts
int maxAttempts
Specifies how often the test is executed at most.Either this or
value()are required. The value must be greater thanminSuccess().- Default:
- 0
-
-