Annotation Interface MethodSource
ArgumentsSourcewhich provides access to values returned from factory methods of the class in which this annotation is declared or from static factory methods in external classes referenced by fully qualified method name.
Each factory method must generate a stream of arguments,
and each set of "arguments" within the "stream" will be provided as the physical
arguments for individual invocations of the annotated
@ParameterizedTest method. Generally speaking this
translates to a
Stream<Arguments>); however, the actual concrete return type
can take on many forms. In this context, a "stream" is anything that JUnit
can reliably convert into a
Stream, such as
Iterable, an array of objects, or an array of primitives. Each set of
"arguments" within the "stream" can be supplied as an instance of
Arguments, an array of objects (e.g.,
String, etc.), or a single value if the parameterized test
method accepts a single argument.
Please note that a one-dimensional array of objects supplied as a set of
"arguments" will be handled differently than other types of arguments.
Specifically, all of the elements of a one-dimensional array of objects will
be passed as individual physical arguments to the
method. This behavior can be seen in the table below for the
static Stream<Object> factory() method: the
method accepts individual
int arguments rather than
Object array. In contrast, any multidimensional array
supplied as a set of "arguments" will be passed as a single physical argument
@ParameterizedTest method without modification. This behavior
can be seen in the table below for the
static Stream<int> factory()
static Stream<Object> factory() methods: the
@ParameterizedTest methods for those factories accept individual
Object arguments, respectively.
The following table displays compatible method signatures for parameterized test methods and their corresponding factory methods.
Factory methods within the test class must be
static unless the
test instance lifecycle mode is used; whereas, factory methods in external
classes must always be
Factory methods can declare parameters, which will be provided by registered
Optional Element Summary
valueString valueThe names of factory methods within the test class or in external classes to use as sources for arguments.
Factory methods in external classes must be referenced by fully qualified method name — for example,
com.example.TopLevelClass$NestedClass#classMethodfor a factory method in a static nested class.
If no factory method names are declared, a method within the test class that has the same name as the test method will be used as the factory method by default.
For further information, see the class-level Javadoc.