@ParameterizedClass is used to signal that the annotated class is
a parameterized test class.
A @ParameterizedClass 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 class.
The provided arguments can either be injected into fields annotated with
@Parameter or passed to the unique constructor of the
parameterized class. If a @Parameter-annotated field is declared in
the parameterized class or one of its superclasses, field injection will be
used. Otherwise, constructor injection will be used.
A @ParameterizedClass constructor may declare additional
parameters at the end of its parameter list to be resolved by other
ParameterResolvers
(e.g., TestInfo, TestReporter, etc.). Specifically, such a
constructor 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 class at the same index in
the constructor's formal parameter list. An aggregator is any
parameter of type
ArgumentsAccessor
or any parameter annotated with
@AggregateWith.
Fields annotated with @Parameter must be declared according to the
following rules.
@Parameter(index) annotation. The
index may be omitted if there is only one indexed parameter. If there are at
least two indexed parameter declarations, there must be declarations for all
indexes from 0 to the largest declared index.@Parameter annotation.@Parameter.In this context, an indexed parameter is an argument for a given
index in the Arguments provided by an ArgumentsProvider that
is injected into a field annotated with @Parameter(index). An
aggregator is any @Parameter-annotated field of type
ArgumentsAccessor
or any field annotated with
@AggregateWith.
@Parameter-annotated fields or constructor 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).
If you wish to execute custom code before or after each invocation of the
parameterized class, you may declare methods annotated with
@BeforeParameterizedClassInvocation
or
@AfterParameterizedClassInvocation.
This can, for example, be useful to initialize the arguments before they are
used.
@ParameterizedClass may also be used as a meta-annotation in
order to create a custom composed annotation that inherits the
semantics of @ParameterizedClass.
This annotation is inherited to subclasses.
Parameter, BeforeParameterizedClassInvocation, AfterParameterizedClassInvocation, ParameterizedTest, 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 class that implement
|
| public String | name()
The display name to be used for individual invocations of the parameterized class; never blank or consisting solely of whitespace. |
| public boolean | quoteTextArguments()
Configure whether to enclose text-based argument values in quotes within display names. |
| allowZeroInvocations | back to summary |
|---|---|
| public boolean allowZeroInvocations() Configure whether zero invocations are allowed for this parameterized class. 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 class 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 class; 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 class accepts
| |