Annotation Interface RepeatedTest
@RepeatedTest
is used to signal that the annotated method is a
test template method that should be repeated a specified number of times with a configurable display
name.
Each invocation of the repeated test behaves like the execution of a
regular @Test
method with full support for the same lifecycle
callbacks and extensions. In addition, the current repetition and total
number of repetitions can be accessed by having the RepetitionInfo
injected.
@RepeatedTest
methods must not be private
or static
and must return void
.
@RepeatedTest
methods may optionally declare parameters to be
resolved by ParameterResolvers
.
@RepeatedTest
may also be used as a meta-annotation in order to
create a custom composed annotation that inherits the semantics
of @RepeatedTest
.
Test Execution Order
By default, test methods will be ordered using an algorithm that is
deterministic but intentionally nonobvious. This ensures that subsequent runs
of a test suite execute test methods in the same order, thereby allowing for
repeatable builds. In this context, a test method is any instance
method that is directly annotated or meta-annotated with @Test
,
@RepeatedTest
, @ParameterizedTest
, @TestFactory
, or
@TestTemplate
.
Although true unit tests typically should not rely on the order
in which they are executed, there are times when it is necessary to enforce
a specific test method execution order — for example, when writing
integration tests or functional tests where the sequence of
the tests is important, especially in conjunction with
@TestInstance(Lifecycle.PER_CLASS)
.
To control the order in which test methods are executed, annotate your
test class or test interface with @TestMethodOrder
and specify the desired MethodOrderer
implementation.
- Since:
- 5.0
- See Also:
DisplayName
,RepetitionInfo
,TestTemplate
,TestInfo
,Test
-
Required Element Summary
-
Optional Element Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic String
Placeholder for the current repetition count of a@RepeatedTest
method:{currentRepetition}
static String
static String
Long display name pattern for a repeated test: "{displayName} :: repetition {currentRepetition} of {totalRepetitions}"static String
Short display name pattern for a repeated test: "repetition {currentRepetition} of {totalRepetitions}"static String
Placeholder for the total number of repetitions of a@RepeatedTest
method:{totalRepetitions}
-
Field Details
-
DISPLAY_NAME_PLACEHOLDER
- See Also:
- Constant Field Values
-
CURRENT_REPETITION_PLACEHOLDER
Placeholder for the current repetition count of a@RepeatedTest
method:{currentRepetition}
- See Also:
- Constant Field Values
-
TOTAL_REPETITIONS_PLACEHOLDER
Placeholder for the total number of repetitions of a@RepeatedTest
method:{totalRepetitions}
- See Also:
- Constant Field Values
-
SHORT_DISPLAY_NAME
Short display name pattern for a repeated test: "repetition {currentRepetition} of {totalRepetitions}" -
LONG_DISPLAY_NAME
Long display name pattern for a repeated test: "{displayName} :: repetition {currentRepetition} of {totalRepetitions}"
-
-
Element Details
-
value
int valueThe number of repetitions.- Returns:
- the number of repetitions; must be greater than zero
-
-
-
name
String nameThe display name for each repetition of the repeated test.Supported placeholders
Defaults to
SHORT_DISPLAY_NAME
, resulting in names such as"repetition 1 of 2"
,"repetition 2 of 2"
, etc.Can be set to
, resulting in names such asLONG_DISPLAY_NAME
"myRepeatedTest() :: repetition 1 of 2"
,"myRepeatedTest() :: repetition 2 of 2"
, etc.Alternatively, you can provide a custom display name, optionally using the aforementioned placeholders.
- Returns:
- a custom display name; never blank or consisting solely of whitespace
- See Also:
SHORT_DISPLAY_NAME
,LONG_DISPLAY_NAME
,DISPLAY_NAME_PLACEHOLDER
,CURRENT_REPETITION_PLACEHOLDER
,TOTAL_REPETITIONS_PLACEHOLDER
,TestInfo.getDisplayName()
- Default:
- "repetition {currentRepetition} of {totalRepetitions}"
-