Types of DynamicTest
Let's learn how to dynamically test simple and nested methods in JUnit 5.
We'll cover the following
There are two types of dynamic tests:
- Simple
DynamicTest
- Nested
DynamicTest
Simple DynamicTest
All test cases we’ve created so far are static. They’re defined at org.junit.jupiter.api.TestFactory
annotation.
The method annotated with @TestFactory
must return a Stream
, Collection
, Iterable
, or Iterator
of org.junit.jupiter.api.DynamicNode
objects. The DynamicNode
is abstract. It has two subclasses:
- The
org.junit.jupiter.api.DynamicContainer
subclass is the container of other DynamicNode objects. - The
org.junit.jupiter.api.DynamicTest
subclass is a generated test case.
Get hands-on with 1400+ tech skills courses.