Skip to content

Commit c1a6ae7

Browse files
committed
Document dynamic test lifecycle in the User Guide
Closes: #374
1 parent f7b93a3 commit c1a6ae7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

documentation/src/docs/asciidoc/writing-tests.adoc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,15 @@ A `DynamicTest` is a test case generated at runtime.
302302
It is composed of a _display name_ and an `Executable`. `Executable` is a `@FunctionalInterface`
303303
which means that the implementations of dynamic tests can be provided as _lambda expressions_
304304
or _method references_.
305-
Note that the execution lifecycle of dynamic tests is quite different than it is for standard `@Test` cases.
306-
Specifically, `@BeforeEach` and `@AfterEach` methods and their corresponding extension callbacks
307-
are not executed for dynamic tests.
308-
The execution of those callbacks would not be useful in most dynamic testing scenarios
309-
since variables used in lambdas are bound to instance variables at execution time of the factory method
310-
rather than execution time of the lambda itself.
305+
306+
.Dynamic Test Lifecycle
307+
WARNING: The execution lifecycle of a dynamic test is quite different than it is for a
308+
standard `@Test` case. Specifically, there are not any lifecycle callbacks for dynamic
309+
tests. This means that `@BeforeEach` and `@AfterEach` methods and their corresponding
310+
extension callbacks are not executed for dynamic tests. In other words, if you access
311+
fields from the test instance within a lambda expression for a dynamic test, those fields
312+
will not be reset by callback methods or extensions between the execution of dynamic
313+
tests generated by the same `@TestFactory` method.
311314

312315
As of JUnit Jupiter {jupiter-version}, dynamic tests must always be created by factory
313316
methods; however, this might be complemented by a registration facility in a later

0 commit comments

Comments
 (0)