Skip to content

Commit ba422ca

Browse files
committed
Document in User Guide and Release Notes
1 parent 8c958eb commit ba422ca

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

‎documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0.adoc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ repository on GitHub.
4545
[[release-notes-6.1.0-M1-junit-jupiter-new-features-and-improvements]]
4646
==== New Features and Improvements
4747

48-
* ❓
48+
* Introduce new `dynamicTest(Consumer<? super Configuration>)` factory method for dynamic
49+
tests. It allows configuring the `ExecutionMode` of the dynamic test in addition to its
50+
display name, test source URI, and executable.
51+
* Introduce new `dynamicContainer(Consumer<? super Configuration>)` factory method for
52+
dynamic containers. It allows configuring the `ExecutionMode` of the dynamic container
53+
and/or its children in addition to its display name, test source URI, and children.
4954

5055

5156
[[release-notes-6.1.0-M1-junit-vintage]]

‎documentation/src/docs/asciidoc/user-guide/writing-tests.adoc‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,29 @@ implementations.
31063106
`UriSource` ::
31073107
If none of the above `TestSource` implementations are applicable.
31083108

3109+
[[writing-tests-dynamic-tests-parallel-execution]]
3110+
==== Parallel Execution
3111+
3112+
Dynamic tests and containers support
3113+
<<writing-tests-parallel-execution, parallel execution>>. You can configure their
3114+
`ExecutionMode` by using the `dynamicTest(Consumer)` and `dynamicContainer(Consumer)`
3115+
factory methods as illustrated by the following example.
3116+
3117+
[source,java,indent=0]
3118+
----
3119+
include::{testDir}/example/DynamicTestsDemo.java[tags=execution_mode]
3120+
----
3121+
3122+
Executing the above test factory method results in the following test tree and execution
3123+
modes:
3124+
3125+
* dynamicTestsWithConfiguredExecutionMode() -- `CONCURRENT` (from `@Execution` annotation)
3126+
** Container A -- `CONCURRENT` (from `@Execution` annotation)
3127+
*** not null -- `SAME_THREAD` (from `executionMode(...)` call)
3128+
*** properties -- `CONCURRENT` (from `@Execution` annotation)
3129+
**** length > 0 -- `CONCURRENT` (from `executionMode(...)` call)
3130+
**** not empty -- `SAME_THREAD` (from `childExecutionMode(...)` call)
3131+
** ... (same for "Container B" and "Container C")
31093132

31103133
[[writing-tests-declarative-timeouts]]
31113134
=== Timeouts

‎documentation/src/test/java/example/DynamicTestsDemo.java‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import static org.junit.jupiter.api.Assertions.assertTrue;
1919
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
2020
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
21+
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;
22+
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD;
2123

2224
import java.util.Arrays;
2325
import java.util.Collection;
@@ -35,6 +37,7 @@
3537
import org.junit.jupiter.api.Tag;
3638
import org.junit.jupiter.api.TestFactory;
3739
import org.junit.jupiter.api.function.ThrowingConsumer;
40+
import org.junit.jupiter.api.parallel.Execution;
3841

3942
// end::user_guide[]
4043
// @formatter:off
@@ -163,6 +166,44 @@ Stream<DynamicNode> dynamicTestsWithContainers() {
163166
)));
164167
}
165168

169+
// end::user_guide[]
170+
// tag::execution_mode[]
171+
@TestFactory
172+
@Execution(CONCURRENT) // <1>
173+
Stream<DynamicNode> dynamicTestsWithConfiguredExecutionMode() {
174+
return Stream.of("A", "B", "C")
175+
.map(input ->
176+
dynamicContainer(outer -> outer
177+
.displayName("Container " + input)
178+
.children(
179+
dynamicTest(config -> config
180+
.displayName("not null")
181+
.executionMode(SAME_THREAD) // <2>
182+
.executable(() -> assertNotNull(input))
183+
),
184+
dynamicContainer(inner -> inner
185+
.displayName("properties")
186+
.executionMode(CONCURRENT) // <3>
187+
.childExecutionMode(SAME_THREAD) // <4>
188+
.children(
189+
dynamicTest(config -> config
190+
.displayName("length > 0")
191+
.executionMode(CONCURRENT) // <5>
192+
.executable(() -> assertTrue(input.length() > 0))
193+
),
194+
dynamicTest(config -> config
195+
.displayName("not empty")
196+
.executable(() -> assertFalse(input.isEmpty()))
197+
)
198+
)
199+
)
200+
)
201+
)
202+
);
203+
}
204+
// end::execution_mode[]
205+
206+
// tag::user_guide[]
166207
@TestFactory
167208
DynamicNode dynamicNodeSingleTest() {
168209
return dynamicTest("'pop' is a palindrome", () -> assertTrue(isPalindrome("pop")));

0 commit comments

Comments
 (0)