@API(value=Experimental) public class DynamicTest extends java.lang.Object
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, Consumer)
,
Test
,
TestFactory
,
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. |
java.lang.String |
getDisplayName()
Get the display name of this
DynamicTest . |
Executable |
getExecutable()
Get the
executable code block associated with this DynamicTest . |
static <T> java.util.stream.Stream<DynamicTest> |
stream(java.util.Iterator<T> inputGenerator,
java.util.function.Function<? super T,java.lang.String> displayNameGenerator,
java.util.function.Consumer<? super T> testExecutor)
Generate a stream of dynamic tests based on the supplied generators
and test executor.
|
java.lang.String |
toString() |
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 null
stream(Iterator, Function, Consumer)
public static <T> java.util.stream.Stream<DynamicTest> stream(java.util.Iterator<T> inputGenerator, java.util.function.Function<? super T,java.lang.String> displayNameGenerator, java.util.function.Consumer<? super T> testExecutor)
Use this method when the set of dynamic tests is nondeterministic in nature.
The supplied inputGenerator
is responsible for generating
input values. A DynamicTest
will be added to the resulting
stream for each dynamically generated input value, using the supplied
displayNameGenerator
and testExecutor
.
T
- the type of input generated by the inputGenerator
and used by the displayNameGenerator
and testExecutor
inputGenerator
- an Iterator
that serves as a dynamic
input generator; never null
displayNameGenerator
- a function that generates a display name
based on an input value; never null
testExecutor
- a consumer that executes a test based on an
input value; never null
null
dynamicTest(String, Executable)
public java.lang.String getDisplayName()
DynamicTest
.public Executable getExecutable()
executable
code block associated with this DynamicTest
.public java.lang.String toString()
toString
in class java.lang.Object