Class DynamicTest
- java.lang.Object
-
- org.junit.jupiter.api.DynamicNode
-
- org.junit.jupiter.api.DynamicTest
-
@API(status=MAINTAINED, since="5.3") public class DynamicTest extends DynamicNodeADynamicTestis a test case generated at runtime.It is composed of a display name and an
Executable.Instances of
DynamicTestmust be generated by factory methods annotated with@TestFactory.Note that dynamic tests are quite different from standard
@Testcases since callbacks such as@BeforeEachand@AfterEachmethods are not executed for dynamic tests.- Since:
- 5.0
- See Also:
dynamicTest(String, Executable),stream(Iterator, Function, ThrowingConsumer),Test,TestFactory,DynamicContainer,Executable
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DynamicTestdynamicTest(java.lang.String displayName, java.net.URI testSourceUri, Executable executable)Factory for creating a newDynamicTestfor the supplied display name, custom test sourceURI, and executable code block.static DynamicTestdynamicTest(java.lang.String displayName, Executable executable)Factory for creating a newDynamicTestfor the supplied display name and executable code block.ExecutablegetExecutable()Get theexecutablecode block associated with thisDynamicTest.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<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.-
Methods inherited from class org.junit.jupiter.api.DynamicNode
getDisplayName, getTestSourceUri, toString
-
-
-
-
Method Detail
-
dynamicTest
public static DynamicTest dynamicTest(java.lang.String displayName, Executable executable)
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:
stream(Iterator, Function, ThrowingConsumer)
-
dynamicTest
public static DynamicTest dynamicTest(java.lang.String displayName, java.net.URI testSourceUri, Executable executable)
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(Iterator, Function, ThrowingConsumer)
-
stream
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)
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:
dynamicTest(String, Executable),stream(Stream, Function, ThrowingConsumer)
-
stream
@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)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:
dynamicTest(String, Executable),stream(Iterator, Function, ThrowingConsumer)
-
getExecutable
public Executable getExecutable()
Get theexecutablecode block associated with thisDynamicTest.
-
-