Package org.junit.jupiter.api
Class DynamicTest
- java.lang.Object
-
- org.junit.jupiter.api.DynamicNode
-
- org.junit.jupiter.api.DynamicTest
-
@API(status=EXPERIMENTAL, since="5.0") public class DynamicTest extends DynamicNode
ADynamicTest
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:
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 DynamicTest
dynamicTest(String displayName, URI testSourceUri, Executable executable)
Factory for creating a newDynamicTest
for the supplied display name, custom test sourceURI
, and executable code block.static DynamicTest
dynamicTest(String displayName, Executable executable)
Factory for creating a newDynamicTest
for the supplied display name and executable code block.Executable
getExecutable()
Get theexecutable
code block associated with thisDynamicTest
.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 supplied generators and test executor.-
Methods inherited from class org.junit.jupiter.api.DynamicNode
getDisplayName, getTestSourceUri, toString
-
-
-
-
Method Detail
-
dynamicTest
public static DynamicTest dynamicTest(String displayName, Executable executable)
Factory for creating a newDynamicTest
for the supplied display name and executable code block.- Parameters:
displayName
- the display name for the dynamic test; nevernull
or blankexecutable
- the executable code block for the dynamic test; nevernull
- See Also:
stream(Iterator, Function, ThrowingConsumer)
-
dynamicTest
public static DynamicTest dynamicTest(String displayName, URI testSourceUri, Executable executable)
Factory for creating a newDynamicTest
for the supplied display name, custom test sourceURI
, and executable code block.- Parameters:
displayName
- the display name for the dynamic test; nevernull
or blanktestSourceUri
- a custom test source URI for the dynamic test; may benull
if the framework should generate the test source based on the@TestFactory
methodexecutable
- the executable code block for the dynamic test; nevernull
- Since:
- 5.3
- See Also:
stream(Iterator, Function, ThrowingConsumer)
-
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 supplied generators and test executor.Use this method when the set of dynamic tests is nondeterministic in nature.
The supplied
inputGenerator
is responsible for generating input values. ADynamicTest
will be added to the resulting stream for each dynamically generated input value, using the supplieddisplayNameGenerator
andtestExecutor
.- Type Parameters:
T
- the type of input generated by theinputGenerator
and used by thedisplayNameGenerator
andtestExecutor
- Parameters:
inputGenerator
- anIterator
that serves as a dynamic input generator; nevernull
displayNameGenerator
- a function that generates a display name based on an input value; nevernull
testExecutor
- a consumer that executes a test based on an input value; nevernull
- Returns:
- a stream of dynamic tests based on the supplied generators and
executor; never
null
- See Also:
dynamicTest(String, Executable)
-
getExecutable
public Executable getExecutable()
Get theexecutable
code block associated with thisDynamicTest
.
-
-