Top Description Fields Methods
org.junit.jupiter.params

public @Interface ParameterizedTest

extends Annotation
Annotations
@Target:ANNOTATION_TYPE, METHOD
@Retention:RUNTIME
@Documented
@API
status:STABLE
since:5.7
@TestTemplate
@ExtendWith:ParameterizedTestExtension
@SuppressWarnings:exports
Static Imports
org.apiguardian.api.API.Status.DEPRECATED, .API.Status.EXPERIMENTAL, .API.Status.MAINTAINED, .API.Status.STABLE

@ParameterizedTest is used to signal that the annotated method is a parameterized test method.

Such methods must not be private or static.

Arguments Providers and Sources

@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.

Formal Parameter List

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.

  1. Zero or more indexed parameters must be declared first.
  2. Zero or more aggregators must be declared next.
  3. Zero or more parameters supplied by other 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.

Argument Conversion

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).

Composed Annotations

@ParameterizedTest may also be used as a meta-annotation in order to create a custom composed annotation that inherits the semantics of @ParameterizedTest.

Inheritance

@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.

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
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

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String

Method Summary

Modifier and TypeMethod and Description
public boolean
allowZeroInvocations()

Configure whether zero invocations are allowed for this parameterized test.

public ArgumentCountValidationMode
argumentCountValidation()

Configure how the number of arguments provided by an ArgumentsSource are validated.

public boolean
autoCloseArguments()

Configure whether all arguments of the parameterized test that implement AutoCloseable will be closed after their corresponding invocation.

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.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Field Detail

ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDERback to summary
public static final String ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER

See ParameterizedInvocationConstants#ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.11
See Also
name, ParameterizedInvocationConstants#ARGUMENT_SET_NAME_PLACEHOLDER, ParameterizedInvocationConstants#ARGUMENTS_WITH_NAMES_PLACEHOLDER, ParameterizedInvocationConstants#DEFAULT_DISPLAY_NAME, org.junit.jupiter.params.provider.Arguments#argumentSet(String, Object...)
ARGUMENT_SET_NAME_PLACEHOLDERback to summary
public static final String ARGUMENT_SET_NAME_PLACEHOLDER

Deprecated

since 5.13.

Please reference ParameterizedInvocationConstants#ARGUMENT_SET_NAME_PLACEHOLDER instead.

See ParameterizedInvocationConstants#ARGUMENT_SET_NAME_PLACEHOLDER.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.11
See Also
name, ParameterizedInvocationConstants#ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER, org.junit.jupiter.params.provider.Arguments#argumentSet(String, Object...)
ARGUMENTS_PLACEHOLDERback to summary
public static final String ARGUMENTS_PLACEHOLDER

Deprecated

since 5.13.

Please reference ParameterizedInvocationConstants#ARGUMENTS_PLACEHOLDER instead.

See ParameterizedInvocationConstants#ARGUMENTS_PLACEHOLDER.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.3
See Also
name
ARGUMENTS_WITH_NAMES_PLACEHOLDERback to summary
public static final String ARGUMENTS_WITH_NAMES_PLACEHOLDER

Deprecated

since 5.13.

Please reference ParameterizedInvocationConstants#ARGUMENTS_WITH_NAMES_PLACEHOLDER instead.

See ParameterizedInvocationConstants#ARGUMENTS_WITH_NAMES_PLACEHOLDER.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.6
See Also
name, ParameterizedInvocationConstants#ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER
DEFAULT_DISPLAY_NAMEback to summary
public static final String DEFAULT_DISPLAY_NAME

Deprecated

since 5.13.

Please reference ParameterizedInvocationConstants#DEFAULT_DISPLAY_NAME instead.

See ParameterizedInvocationConstants#DEFAULT_DISPLAY_NAME.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.3
See Also
name, ParameterizedInvocationConstants#DISPLAY_NAME_PLACEHOLDER, ParameterizedInvocationConstants#INDEX_PLACEHOLDER, ParameterizedInvocationConstants#ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER
DISPLAY_NAME_PLACEHOLDERback to summary
public static final String DISPLAY_NAME_PLACEHOLDER

Deprecated

since 5.13.

Please reference ParameterizedInvocationConstants#DISPLAY_NAME_PLACEHOLDER instead.

See ParameterizedInvocationConstants#DISPLAY_NAME_PLACEHOLDER.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.3
See Also
name
INDEX_PLACEHOLDERback to summary
public static final String INDEX_PLACEHOLDER

Deprecated

since 5.13.

Please reference ParameterizedInvocationConstants#INDEX_PLACEHOLDER instead.

See ParameterizedInvocationConstants#INDEX_PLACEHOLDER.

Annotations
@API
status:DEPRECATED
since:5.13
@Deprecated
since:5.13
Since
5.3
See Also
name, ParameterizedInvocationConstants#DEFAULT_DISPLAY_NAME

Method Detail

allowZeroInvocationsback to summary
public boolean allowZeroInvocations()

Configure whether zero invocations are allowed for this parameterized test.

Set this attribute to true if the absence of invocations is expected in some cases and should not cause a test failure.

Defaults to false.

Annotations
@API
status:MAINTAINED
since:5.13.3
Since
5.12
argumentCountValidationback to summary
public ArgumentCountValidationMode argumentCountValidation()

Configure how the number of arguments provided by an ArgumentsSource are validated.

Defaults to ArgumentCountValidationMode#DEFAULT.

When an ArgumentsSource provides more arguments than declared by the parameterized test method, there might be a bug in the method or the ArgumentsSource. By default, the additional arguments are ignored. argumentCountValidation allows you to control how additional arguments are handled. The default can be configured via the junit.jupiter.params.argumentCountValidation configuration parameter (see the User Guide for details on configuration parameters).

Annotations
@API
status:MAINTAINED
since:5.13.3
Since
5.12
See Also
ArgumentCountValidationMode
autoCloseArgumentsback to summary
public boolean autoCloseArguments()

Configure whether all arguments of the parameterized test that implement AutoCloseable will be closed after their corresponding invocation.

Defaults to true.

Warning

if an argument that implements AutoCloseable is reused for multiple invocations of the same parameterized test method, you must set autoCloseArguments to false to ensure that the argument is not closed between invocations.

Annotations
@API
status:STABLE
since:5.10
Since
5.8
See Also
java.lang.AutoCloseable
nameback 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 {default_display_name}.

If the default display name flag ({default_display_name}) is not overridden, JUnit will:

  • Look up the junit.jupiter.params.displayname.default configuration parameter and use it if available. The configuration parameter can be supplied via the Launcher API, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit Platform configuration file (i.e., a file named junit-platform.properties in the root of the class path). Consult the User Guide for further information.
  • Otherwise, [{index}] {argumentSetNameOrArgumentsWithNames} will be used.

Supported placeholders

  • {displayName}
  • {index}
  • {argumentSetName}
  • {arguments}
  • {argumentsWithNames}
  • {argumentSetNameOrArgumentsWithNames}
  • "{0}", "{1}", etc.: an individual argument (0-based)

For the latter, you may use java.text.MessageFormat patterns to customize formatting (for example, {0,number,#.###}). Please note that the original arguments are passed when formatting, regardless of any implicit or explicit argument conversions.

Note that {default_display_name} is a flag rather than a placeholder.

See Also
java.text.MessageFormat, quoteTextArguments()
quoteTextArgumentsback to summary
public boolean quoteTextArguments()

Configure whether to enclose text-based argument values in quotes within display names.

Defaults to true.

In this context, any CharSequence (such as a String) or Character is considered text. A CharSequence is wrapped in double quotes ("), and a Character is wrapped in single quotes (').

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 \\r and \\n, respectively. In addition, any ISO control character will be represented as a question mark (?) in the quoted text.

For example, given a string argument "line 1\nline 2", the representation in the display name would be "\"line 1\\nline 2\"" (printed as "line 1\nline 2") with the newline character escaped as "\\n". Similarly, given a string argument "\t", the representation in the display name would be "\"\\t\"" (printed as "\t") instead of a blank string or invisible tab character. The same applies for a character argument '\t', whose representation in the display name would be "'\\t'" (printed as '\t').

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 3.14 as a float argument that was converted from "3.14" as an input string, "3.14" will be present in the display name instead of 3.14.

Annotations
@API
status:EXPERIMENTAL
since:6.0
Since
6.0
See Also
name()