@API(status=MAINTAINED,
since="5.3")
public class DynamicTest
extends DynamicNode
DynamicTest is a test case generated at runtime.
It is composed of a display name
and an Executable.
Instances of DynamicTest must be generated by factory methods
annotated with @TestFactory.
Note that dynamic tests are quite different from standard @Test
cases since callbacks such as @BeforeEach and
@AfterEach methods are not executed for dynamic tests.
dynamicTest(String, Executable),
stream(Iterator, Function, ThrowingConsumer),
Test,
TestFactory,
DynamicContainer,
Executable| Modifier and Type | Field and Description |
|---|---|
private Executable |
executable |
| Modifier | Constructor and Description |
|---|---|
private |
DynamicTest(java.lang.String displayName,
java.net.URI testSourceUri,
Executable executable) |
| Modifier and Type | Method and Description |
|---|---|
static DynamicTest |
dynamicTest(java.lang.String displayName,
Executable executable)
Factory for creating a new
DynamicTest for the supplied display
name and executable code block. |
static DynamicTest |
dynamicTest(java.lang.String displayName,
java.net.URI testSourceUri,
Executable executable)
Factory for creating a new
DynamicTest for the supplied display
name, custom test source URI, and executable code block. |
Executable |
getExecutable()
Get the
executable code block associated with this DynamicTest. |
static <T> java.util.stream.Stream<DynamicTest> |
stream(java.util.Iterator<? extends Named<T>> inputGenerator,
ThrowingConsumer<? super T> testExecutor)
Generate a stream of dynamic tests based on the given generator and test
executor.
|
static <T> java.util.stream.Stream<DynamicTest> |
stream(java.util.Iterator<T> inputGenerator,
java.util.function.Function<? super T,java.lang.String> displayNameGenerator,
ThrowingConsumer<? super T> testExecutor)
Generate a stream of dynamic tests based on the given generator and test
executor.
|
static <T> java.util.stream.Stream<DynamicTest> |
stream(java.util.stream.Stream<? extends Named<T>> inputStream,
ThrowingConsumer<? super T> testExecutor)
Generate a stream of dynamic tests based on the given input stream and
test executor.
|
static <T> java.util.stream.Stream<DynamicTest> |
stream(java.util.stream.Stream<T> inputStream,
java.util.function.Function<? super T,java.lang.String> displayNameGenerator,
ThrowingConsumer<? super T> testExecutor)
Generate a stream of dynamic tests based on the given input stream and
test executor.
|
getDisplayName, getTestSourceUri, toStringprivate final Executable executable
private DynamicTest(java.lang.String displayName,
java.net.URI testSourceUri,
Executable executable)
public static DynamicTest dynamicTest(java.lang.String displayName, Executable executable)
DynamicTest for the supplied display
name and executable code block.displayName - the display name for the dynamic test; never
null or blankexecutable - the executable code block for the dynamic test;
never nullstream(Iterator, Function, ThrowingConsumer)public static DynamicTest dynamicTest(java.lang.String displayName, java.net.URI testSourceUri, Executable executable)
DynamicTest for the supplied display
name, custom test source URI, and executable code block.displayName - the display name for the dynamic test; never
null or blanktestSourceUri - a custom test source URI for the dynamic test; may
be null if the framework should generate the test source based on
the @TestFactory methodexecutable - the executable code block for the dynamic test;
never nullstream(Iterator, Function, ThrowingConsumer)public static <T> java.util.stream.Stream<DynamicTest> stream(java.util.Iterator<T> inputGenerator, java.util.function.Function<? super T,java.lang.String> displayNameGenerator, ThrowingConsumer<? super T> testExecutor)
Use this method when the set of dynamic tests is nondeterministic in
nature or when the input comes from an existing Iterator. See
stream(Stream, Function, ThrowingConsumer) as an alternative.
The given inputGenerator is responsible for generating
input values. A DynamicTest will be added to the resulting
stream for each dynamically generated input value, using the given
displayNameGenerator and testExecutor.
T - the type of input generated by the inputGenerator
and used by the displayNameGenerator and testExecutorinputGenerator - an Iterator that serves as a dynamic
input generator; never nulldisplayNameGenerator - a function that generates a display name
based on an input value; never nulltestExecutor - a consumer that executes a test based on an input
value; never nullnulldynamicTest(String, Executable),
stream(Stream, Function, ThrowingConsumer)@API(status=MAINTAINED,
since="5.7")
public static <T> java.util.stream.Stream<DynamicTest> stream(java.util.stream.Stream<T> inputStream,
java.util.function.Function<? super T,java.lang.String> displayNameGenerator,
ThrowingConsumer<? super T> testExecutor)
Use this method when the set of dynamic tests is nondeterministic in
nature or when the input comes from an existing Stream. See
stream(Iterator, Function, ThrowingConsumer) as an alternative.
The given inputStream is responsible for supplying input values.
A DynamicTest will be added to the resulting stream for each
dynamically supplied input value, using the given displayNameGenerator
and testExecutor.
T - the type of input supplied by the inputStream
and used by the displayNameGenerator and testExecutorinputStream - a Stream that supplies dynamic input values;
never nulldisplayNameGenerator - a function that generates a display name
based on an input value; never nulltestExecutor - a consumer that executes a test based on an input
value; never nullnulldynamicTest(String, Executable),
stream(Iterator, Function, ThrowingConsumer)@API(status=MAINTAINED,
since="5.8")
public static <T> java.util.stream.Stream<DynamicTest> stream(java.util.Iterator<? extends Named<T>> inputGenerator,
ThrowingConsumer<? super T> testExecutor)
Use this method when the set of dynamic tests is nondeterministic in
nature or when the input comes from an existing Iterator. See
stream(Stream, ThrowingConsumer) as an alternative.
The given inputGenerator is responsible for generating
input values and display names. A DynamicTest will be added to
the resulting stream for each dynamically generated input value,
using the given testExecutor.
T - the type of input generated by the inputGenerator
and used by the testExecutorinputGenerator - an Iterator with Named values
that serves as a dynamic input generator; never nulltestExecutor - a consumer that executes a test based on an input
value; never nullnulldynamicTest(String, Executable),
stream(Stream, ThrowingConsumer),
Named@API(status=MAINTAINED,
since="5.8")
public static <T> java.util.stream.Stream<DynamicTest> stream(java.util.stream.Stream<? extends Named<T>> inputStream,
ThrowingConsumer<? super T> testExecutor)
Use this method when the set of dynamic tests is nondeterministic in
nature or when the input comes from an existing Stream. See
stream(Iterator, ThrowingConsumer) as an alternative.
The given inputStream is responsible for supplying input values
and display names. A DynamicTest will be added to the resulting stream for
each dynamically supplied input value, using the given testExecutor.
T - the type of input supplied by the inputStream
and used by the displayNameGenerator and testExecutorinputStream - a Stream that supplies dynamic Named
input values; never nulltestExecutor - a consumer that executes a test based on an input
value; never nullnulldynamicTest(String, Executable),
stream(Iterator, ThrowingConsumer),
Namedpublic Executable getExecutable()
executable code block associated with this DynamicTest.