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.
- Since:
- 5.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic DynamicTestdynamicTest(String displayName, URI testSourceUri, Executable executable) Factory for creating a newDynamicTestfor the supplied display name, custom test sourceURI, and executable code block.static DynamicTestdynamicTest(String displayName, Executable executable) Factory for creating a newDynamicTestfor the supplied display name and executable code block.Get theexecutablecode block associated with thisDynamicTest.static <T> Stream<DynamicTest> stream(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 extends Named<E>,E extends Executable>
Stream<DynamicTest> Generate a stream of dynamic tests based on the given iterator.static <T> Stream<DynamicTest> stream(Iterator<T> inputGenerator, Function<? super T, String> displayNameGenerator, ThrowingConsumer<? super T> testExecutor) Generate a stream of dynamic tests based on the given generator and test executor.static <T> Stream<DynamicTest> 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 extends Named<E>,E extends Executable>
Stream<DynamicTest> Generate a stream of dynamic tests based on the given input stream.static <T> Stream<DynamicTest> stream(Stream<T> inputStream, Function<? super T, String> displayNameGenerator, ThrowingConsumer<? super T> testExecutor) Generate a stream of dynamic tests based on the given input stream and test executor.Methods inherited from class org.junit.jupiter.api.DynamicNode
getDisplayName, getTestSourceUri, toString
-
Method Details
-
dynamicTest
Factory for creating a newDynamicTestfor the supplied display name and executable code block.- Parameters:
displayName- the display name for the dynamic test; nevernullor blankexecutable- the executable code block for the dynamic test; nevernull- See Also:
-
dynamicTest
Factory for creating a newDynamicTestfor the supplied display name, custom test sourceURI, and executable code block.- Parameters:
displayName- the display name for the dynamic test; nevernullor blanktestSourceUri- a custom test source URI for the dynamic test; may benullif the framework should generate the test source based on the@TestFactorymethodexecutable- the executable code block for the dynamic test; nevernull- Since:
- 5.3
- See Also:
-
stream
public static <T> Stream<DynamicTest> stream(Iterator<T> inputGenerator, Function<? super T, String> displayNameGenerator, ThrowingConsumer<? super T> testExecutor) Generate a stream of dynamic tests based on the given generator and test executor.Use this method when the set of dynamic tests is nondeterministic in nature or when the input comes from an existing
Iterator. Seestream(Stream, Function, ThrowingConsumer)as an alternative.The given
inputGeneratoris responsible for generating input values. ADynamicTestwill be added to the resulting stream for each dynamically generated input value, using the givendisplayNameGeneratorandtestExecutor.- Type Parameters:
T- the type of input generated by theinputGeneratorand used by thedisplayNameGeneratorandtestExecutor- Parameters:
inputGenerator- anIteratorthat serves as a dynamic input generator; nevernulldisplayNameGenerator- a function that generates a display name based on an input value; nevernulltestExecutor- a consumer that executes a test based on an input value; nevernull- Returns:
- a stream of dynamic tests based on the given generator and
executor; never
null - See Also:
-
stream
@API(status=MAINTAINED, since="5.7") public static <T> Stream<DynamicTest> stream(Stream<T> inputStream, Function<? super T, String> displayNameGenerator, ThrowingConsumer<? super T> testExecutor) Generate a stream of dynamic tests based on the given input stream and test executor.Use this method when the set of dynamic tests is nondeterministic in nature or when the input comes from an existing
Stream. Seestream(Iterator, Function, ThrowingConsumer)as an alternative.The given
inputStreamis responsible for supplying input values. ADynamicTestwill be added to the resulting stream for each dynamically supplied input value, using the givendisplayNameGeneratorandtestExecutor.- Type Parameters:
T- the type of input supplied by theinputStreamand used by thedisplayNameGeneratorandtestExecutor- Parameters:
inputStream- aStreamthat supplies dynamic input values; nevernulldisplayNameGenerator- a function that generates a display name based on an input value; nevernulltestExecutor- a consumer that executes a test based on an input value; nevernull- Returns:
- a stream of dynamic tests based on the given generator and
executor; never
null - Since:
- 5.7
- See Also:
-
stream
@API(status=MAINTAINED, since="5.8") public static <T> Stream<DynamicTest> stream(Iterator<? extends Named<T>> inputGenerator, ThrowingConsumer<? super T> testExecutor) Generate a stream of dynamic tests based on the given generator and test executor.Use this method when the set of dynamic tests is nondeterministic in nature or when the input comes from an existing
Iterator. Seestream(Stream, ThrowingConsumer)as an alternative.The given
inputGeneratoris responsible for generating input values and display names. ADynamicTestwill be added to the resulting stream for each dynamically generated input value, using the giventestExecutor.- Type Parameters:
T- the type of input generated by theinputGeneratorand used by thetestExecutor- Parameters:
inputGenerator- anIteratorwithNamedvalues that serves as a dynamic input generator; nevernulltestExecutor- a consumer that executes a test based on an input value; nevernull- Returns:
- a stream of dynamic tests based on the given generator and
executor; never
null - Since:
- 5.8
- See Also:
-
stream
@API(status=MAINTAINED, since="5.8") public static <T> Stream<DynamicTest> 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.Use this method when the set of dynamic tests is nondeterministic in nature or when the input comes from an existing
Stream. Seestream(Iterator, ThrowingConsumer)as an alternative.The given
inputStreamis responsible for supplying input values and display names. ADynamicTestwill be added to the resulting stream for each dynamically supplied input value, using the giventestExecutor.- Type Parameters:
T- the type of input supplied by theinputStreamand used by thedisplayNameGeneratorandtestExecutor- Parameters:
inputStream- aStreamthat supplies dynamicNamedinput values; nevernulltestExecutor- a consumer that executes a test based on an input value; nevernull- Returns:
- a stream of dynamic tests based on the given generator and
executor; never
null - Since:
- 5.8
- See Also:
-
stream
@API(status=EXPERIMENTAL, since="5.11") public static <T extends Named<E>,E extends Executable> Stream<DynamicTest> stream(Iterator<? extends T> iterator) Generate a stream of dynamic tests based on the given iterator.Use this method when the set of dynamic tests is nondeterministic in nature or when the input comes from an existing
Iterator. Seestream(Stream)as an alternative.The given
iteratoris responsible for supplyingNamedinput values that provide anExecutablecode block. ADynamicTestcomprised of both parts will be added to the resulting stream for each dynamically supplied input value.- Type Parameters:
T- the type of input supplied by theinputStream- Parameters:
iterator- anIteratorthat supplies named executables; nevernull- Returns:
- a stream of dynamic tests based on the given iterator; never
null - Since:
- 5.11
- See Also:
-
stream
@API(status=EXPERIMENTAL, since="5.11") public static <T extends Named<E>,E extends Executable> Stream<DynamicTest> stream(Stream<? extends T> inputStream) Generate a stream of dynamic tests based on the given input stream.Use this method when the set of dynamic tests is nondeterministic in nature or when the input comes from an existing
Stream. Seestream(Iterator)as an alternative.The given
inputStreamis responsible for supplyingNamedinput values that provide anExecutablecode block. ADynamicTestcomprised of both parts will be added to the resulting stream for each dynamically supplied input value.- Type Parameters:
T- the type of input supplied by theinputStream- Parameters:
inputStream- aStreamthat supplies named executables; nevernull- Returns:
- a stream of dynamic tests based on the given stream; never
null - Since:
- 5.11
- See Also:
-
getExecutable
Get theexecutablecode block associated with thisDynamicTest.
-