Top Description Fields Constructors Methods
org.junit.jupiter.api

public Class DynamicTest

extends DynamicNode
Class Inheritance
Annotations
@API
status:MAINTAINED
since:5.3
Static Imports
java.util.Spliterator.ORDERED, .Spliterators.spliteratorUnknownSize, org.apiguardian.api.API.Status.MAINTAINED

A 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
dynamicTest(String, Executable), stream(Iterator, Function, ThrowingConsumer), Test, TestFactory, DynamicContainer, Executable

Field Summary

Modifier and TypeField and Description
private final Executable

Constructor Summary

AccessConstructor and Description
private
DynamicTest(String displayName, URI testSourceUri, Executable executable)

Method Summary

Modifier and TypeMethod and Description
public static DynamicTest
dynamicTest(String
the display name for the dynamic test; never null or blank
displayName
,
Executable
the executable code block for the dynamic test; never null
executable
)

Factory for creating a new DynamicTest for the supplied display name and executable code block.

public static DynamicTest
dynamicTest(String
the display name for the dynamic test; never null or blank
displayName
,
URI
a custom test source URI for the dynamic test; may be null if the framework should generate the test source based on the @TestFactory method
testSourceUri
,
Executable
the executable code block for the dynamic test; never null
executable
)

Factory for creating a new DynamicTest for the supplied display name, custom test source URI, and executable code block.

public Executable
getExecutable()

Get the executable code block associated with this DynamicTest.

public static <
the type of input generated by the inputGenerator and used by the displayNameGenerator and testExecutor
T
>
Stream<DynamicTest>

Returns:

a stream of dynamic tests based on the given generator and executor; never null
stream
(Iterator<T>
an Iterator that serves as a dynamic input generator; never null
inputGenerator
,
Function<? super T, String>
a function that generates a display name based on an input value; never null
displayNameGenerator
,
ThrowingConsumer<? super T>
a consumer that executes a test based on an input value; never null
testExecutor
)

Generate a stream of dynamic tests based on the given generator and test executor.

public static <
the type of input supplied by the inputStream and used by the displayNameGenerator and testExecutor
T
>
Stream<DynamicTest>

Returns:

a stream of dynamic tests based on the given generator and executor; never null
stream
(Stream<T>
a Stream that supplies dynamic input values; never null
inputStream
,
Function<? super T, String>
a function that generates a display name based on an input value; never null
displayNameGenerator
,
ThrowingConsumer<? super T>
a consumer that executes a test based on an input value; never null
testExecutor
)

Generate a stream of dynamic tests based on the given input stream and test executor.

public static <
the type of input generated by the inputGenerator and used by the testExecutor
T
>
Stream<DynamicTest>

Returns:

a stream of dynamic tests based on the given generator and executor; never null
stream
(Iterator<? extends Named<T>>
an Iterator with Named values that serves as a dynamic input generator; never null
inputGenerator
,
ThrowingConsumer<? super T>
a consumer that executes a test based on an input value; never null
testExecutor
)

Generate a stream of dynamic tests based on the given generator and test executor.

public static <
the type of input supplied by the inputStream and used by the displayNameGenerator and testExecutor
T
>
Stream<DynamicTest>

Returns:

a stream of dynamic tests based on the given generator and executor; never null
stream
(Stream<? extends Named<T>>
a Stream that supplies dynamic Named input values; never null
inputStream
,
ThrowingConsumer<? super T>
a consumer that executes a test based on an input value; never null
testExecutor
)

Generate a stream of dynamic tests based on the given input stream and test executor.

Inherited from org.junit.jupiter.api.DynamicNode:
getDisplayNamegetTestSourceUritoString

Field Detail

executableback to summary
private final Executable executable

Constructor Detail

DynamicTestback to summary
private DynamicTest(String displayName, URI testSourceUri, Executable executable)

Method Detail

dynamicTestback to summary
public static DynamicTest dynamicTest(String displayName, Executable executable)

Factory for creating a new DynamicTest for the supplied display name and executable code block.

Parameters
displayName:String

the display name for the dynamic test; never null or blank

executable:Executable

the executable code block for the dynamic test; never null

See Also
stream(Iterator, Function, ThrowingConsumer)
dynamicTestback to summary
public static DynamicTest dynamicTest(String displayName, URI testSourceUri, Executable executable)

Factory for creating a new DynamicTest for the supplied display name, custom test source URI, and executable code block.

Parameters
displayName:String

the display name for the dynamic test; never null or blank

testSourceUri:URI

a custom test source URI for the dynamic test; may be null if the framework should generate the test source based on the @TestFactory method

executable:Executable

the executable code block for the dynamic test; never null

Since
5.3
See Also
stream(Iterator, Function, ThrowingConsumer)
getExecutableback to summary
public Executable getExecutable()

Get the executable code block associated with this DynamicTest.

streamback to summary
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. 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.

Parameters
<T>
the type of input generated by the inputGenerator and used by the displayNameGenerator and testExecutor
inputGenerator:Iterator<T>

an Iterator that serves as a dynamic input generator; never null

displayNameGenerator:Function<? super T, String>

a function that generates a display name based on an input value; never null

testExecutor:ThrowingConsumer<? super T>

a consumer that executes a test based on an input value; never null

Returns:Stream<DynamicTest>

a stream of dynamic tests based on the given generator and executor; never null

See Also
dynamicTest(String, Executable), stream(Stream, Function, ThrowingConsumer)
streamback to summary
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. 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.

Parameters
<T>
the type of input supplied by the inputStream and used by the displayNameGenerator and testExecutor
inputStream:Stream<T>

a Stream that supplies dynamic input values; never null

displayNameGenerator:Function<? super T, String>

a function that generates a display name based on an input value; never null

testExecutor:ThrowingConsumer<? super T>

a consumer that executes a test based on an input value; never null

Returns:Stream<DynamicTest>

a stream of dynamic tests based on the given generator and executor; never null

Annotations
@API
status:MAINTAINED
since:5.7
Since
5.7
See Also
dynamicTest(String, Executable), stream(Iterator, Function, ThrowingConsumer)
streamback to summary
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. 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.

Parameters
<T>
the type of input generated by the inputGenerator and used by the testExecutor
inputGenerator:Iterator<? extends Named<T>>

an Iterator with Named values that serves as a dynamic input generator; never null

testExecutor:ThrowingConsumer<? super T>

a consumer that executes a test based on an input value; never null

Returns:Stream<DynamicTest>

a stream of dynamic tests based on the given generator and executor; never null

Annotations
@API
status:MAINTAINED
since:5.8
Since
5.8
See Also
dynamicTest(String, Executable), stream(Stream, ThrowingConsumer), Named
streamback to summary
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. 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.

Parameters
<T>
the type of input supplied by the inputStream and used by the displayNameGenerator and testExecutor
inputStream:Stream<? extends Named<T>>

a Stream that supplies dynamic Named input values; never null

testExecutor:ThrowingConsumer<? super T>

a consumer that executes a test based on an input value; never null

Returns:Stream<DynamicTest>

a stream of dynamic tests based on the given generator and executor; never null

Annotations
@API
status:MAINTAINED
since:5.8
Since
5.8
See Also
dynamicTest(String, Executable), stream(Iterator, ThrowingConsumer), Named