Annotation Type RetryingTest
@RetryingTest is 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 than n
times. 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 all n executions 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, use onExceptions().
@RetryingTest has 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 RetryingTest are 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 -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintSpecifies how often the test is executed at most.intSpecifies the minimum number of successful executions of the test.The display name to be used for individual invocations of the parameterized test; never blank or consisting solely of whitespace.Specifies on which exceptions a failed test is retried.intSpecifies a pause (in milliseconds) between executions.intSpecifies how often the test is executed at most.
-
Field Details
-
DISPLAY_NAME_PLACEHOLDER
Placeholder for the display name of a@RetryingTest:{displayName}- Since:
- 1.7.0
- See Also:
-
INDEX_PLACEHOLDER
Placeholder for the current invocation index of a@RetryingTestmethod (1-based):{index}- Since:
- 1.7.0
- See Also:
-
-
Element Details
-
name
String nameThe 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:
- Default:
"[{index}]"
-
value
-
maxAttempts
int maxAttemptsSpecifies how often the test is executed at most.Either this or
value()are required. The value must be greater thanminSuccess().- Default:
0
-
minSuccess
int minSuccessSpecifies the minimum number of successful executions of the test.The test will be executed at least this number of times. If the test does not complete successfully the given number of times, the test will fail.
Value must be greater than or equal to 1.
- Default:
1
-
suspendForMs
int suspendForMsSpecifies a pause (in milliseconds) between executions.The thread executing this test is sleeping during that time and won't execute other tests, so long suspensions are discouraged.
Value must be greater than or equal to 0.
- Default:
0
-
onExceptions
-