@ParameterizedTest is used to signal that the annotated method is a
parameterized test method.
Such methods must not be private or static.
@ParameterizedTest methods must specify at least one
ArgumentsProvider
via @ArgumentsSource
or a corresponding composed annotation (e.g., @ValueSource,
@CsvSource, etc.). The provider is responsible for providing a
Stream of
Arguments that will be
used to invoke the parameterized test method.
A @ParameterizedTest method may declare additional parameters at
the end of the method's parameter list to be resolved by other
ParameterResolvers
(e.g., TestInfo, TestReporter, etc.). Specifically, a
parameterized test method must declare formal parameters according to the
following rules.
ParameterResolver
implementations must be declared last.In this context, an indexed parameter is an argument for a given
index in the Arguments provided by an ArgumentsProvider that
is passed as an argument to the parameterized method at the same index in the
method's formal parameter list. An aggregator is any parameter of type
ArgumentsAccessor
or any parameter annotated with
@AggregateWith.
Method parameters may be annotated with
@ConvertWith
or a corresponding composed annotation to specify an explicit
ArgumentConverter.
Otherwise, JUnit Jupiter will attempt to perform an implicit
conversion to the target type automatically (see the User Guide for further
details).
@ParameterizedTest may also be used as a meta-annotation in order
to create a custom composed annotation that inherits the semantics
of @ParameterizedTest.
@ParameterizedTest methods are inherited from superclasses as long
as they are not overridden according to the visibility rules of the
Java language. Similarly, @ParameterizedTest methods declared as
interface default methods are inherited as long as they are not
overridden.
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..
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.
ParameterizedClass, org.junit.jupiter.params.provider.Arguments , org.junit.jupiter.params.provider.ArgumentsProvider , org.junit.jupiter.params.provider.ArgumentsSource , org.junit.jupiter.params.provider.CsvFileSource , org.junit.jupiter.params.provider.CsvSource , org.junit.jupiter.params.provider.EnumSource , org.junit.jupiter.params.provider.MethodSource , org.junit.jupiter.params.provider.ValueSource , org.junit.jupiter.params.aggregator.ArgumentsAccessor , org.junit.jupiter.params.aggregator.AggregateWith , org.junit.jupiter.params.converter.ArgumentConverter , org.junit.jupiter.params.converter.ConvertWith
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public ArgumentCountValidationMode | argumentCountValidation()
Configure how the number of arguments provided by an
|
| public boolean | autoCloseArguments()
Configure whether all arguments of the parameterized test that implement
|
| public String | name()
The display name to be used for individual invocations of the parameterized test; never blank or consisting solely of whitespace. |
| public boolean | quoteTextArguments()
Configure whether to enclose text-based argument values in quotes within display names. |
| ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER | back to summary |
|---|---|
| public static final String ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER
Deprecated since 5.13. Please reference
See
| |
| ARGUMENT_SET_NAME_PLACEHOLDER | back to summary |
|---|---|
| public static final String ARGUMENT_SET_NAME_PLACEHOLDER
Deprecated since 5.13. Please reference
See
| |
| ARGUMENTS_PLACEHOLDER | back to summary |
|---|---|
| public static final String ARGUMENTS_PLACEHOLDER
Deprecated since 5.13. Please reference
See
| |
| ARGUMENTS_WITH_NAMES_PLACEHOLDER | back to summary |
|---|---|
| public static final String ARGUMENTS_WITH_NAMES_PLACEHOLDER
Deprecated since 5.13. Please reference
See
| |
| DEFAULT_DISPLAY_NAME | back to summary |
|---|---|
| public static final String DEFAULT_DISPLAY_NAME
Deprecated since 5.13. Please reference
See
| |
| DISPLAY_NAME_PLACEHOLDER | back to summary |
|---|---|
| public static final String DISPLAY_NAME_PLACEHOLDER
Deprecated since 5.13. Please reference
See
| |
| INDEX_PLACEHOLDER | back to summary |
|---|---|
| public static final String INDEX_PLACEHOLDER
See
| |
| allowZeroInvocations | back to summary |
|---|---|
| public boolean allowZeroInvocations() Configure whether zero invocations are allowed for this parameterized test. Set this attribute to Defaults to
| |
| argumentCountValidation | back to summary |
|---|---|
| public ArgumentCountValidationMode argumentCountValidation() Configure how the number of arguments provided by an
Defaults to When an
| |
| autoCloseArguments | back to summary |
|---|---|
| public boolean autoCloseArguments() Configure whether all arguments of the parameterized test that implement
Defaults to Warning if an argument that implements
| |
| name | back to summary |
|---|---|
| public String name() The display name to be used for individual invocations of the parameterized test; never blank or consisting solely of whitespace. Defaults to If the default display name flag
(
Supported placeholders
For the latter, you may use Note that
| |
| quoteTextArguments | back to summary |
|---|---|
| public boolean quoteTextArguments() Configure whether to enclose text-based argument values in quotes within display names. Defaults to In this context, any Special characters in Java strings and characters will be escaped in the
quoted text — for example, carriage returns and line feeds will be
escaped as For example, given a string argument Please note that original source arguments are quoted when generating
a display name, before any implicit or explicit argument conversion is
performed. For example, if a parameterized test accepts
| |