Annotation Interface RetryTest
When a test fails, it will be retried up to the specified number of times. Optionally, a wait period can be specified between retry attempts.
By default, any exception triggers a retry. If withExceptions is specified,
only matching exception types (or any exception in their cause chain) will trigger
a retry — other failures fail fast without retrying.
This annotation automatically includes the RetryExtension, so no additional
@ExtendWith annotation is required.
Usage examples:
@RetryTest(3)
void unstableTest() {
// Test code that might fail intermittently
}
@RetryTest(value = 5, delay = 2)
void testWithDelay() {
// Test that waits 2 seconds between retry attempts
}
@RetryTest(value = 3, withExceptions = IOException.class)
void testRetryOnIoException() {
// Only retries if IOException is thrown (or is a cause)
}
@RetryTest(withExceptions = {SocketTimeoutException.class, ConnectException.class})
void testRetryOnSpecificExceptions() {
// Only retries on specific network exceptions
}- Since:
- 1.0
- Author:
- Erik C. Thauvin
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintThe number of seconds to wait between retry attempts.Optional name for the test template.intThe maximum number of retry attempts for a failing test.Exception types that should trigger a retry.
-
Element Details
-
delay
int delayThe number of seconds to wait between retry attempts.If set to
0(default), no wait occurs between retries. This can be useful for tests that interact with external systems that may need time to recover or stabilize.- Returns:
- the wait time in seconds between retry attempts
- Default:
- 0
-
name
String nameOptional name for the test template. If not specified, a default name will be generated.- Returns:
- the display name for the retry test template
- Default:
- ""
-
value
int valueThe maximum number of retry attempts for a failing test.The test will be executed at most
value()times after the initial failure.- Returns:
- the number of retry attempts. Must be greater than 0
- Default:
- 3
-
withExceptions
Exception types that should trigger a retry.If empty, any exception triggers a retry. If specified, only matching exceptions (or their causes) will be retried.
- Default:
- {}
-