Skip to content

Commit 418131f

Browse files
committed
Document causes of concurrent execution being disabled by default
Resolves #3849.
1 parent a0df73c commit 418131f

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2698,11 +2698,11 @@ junit.jupiter.execution.parallel.mode.default = concurrent
26982698

26992699
The default execution mode is applied to all nodes of the test tree with a few notable
27002700
exceptions, namely test classes that use the `Lifecycle.PER_CLASS` mode or a
2701-
`{MethodOrderer}` (except for `{MethodOrderer_Random}`). In the former case, test authors
2702-
have to ensure that the test class is thread-safe; in the latter, concurrent execution
2703-
might conflict with the configured execution order. Thus, in both cases, test methods in
2704-
such test classes are only executed concurrently if the `@Execution(CONCURRENT)`
2705-
annotation is present on the test class or method.
2701+
`{MethodOrderer}`. In the former case, test authors have to ensure that the test class is
2702+
thread-safe; in the latter, concurrent execution might conflict with the configured
2703+
execution order. Thus, in both cases, test methods in such test classes are only executed
2704+
concurrently if the `@Execution(CONCURRENT)` annotation is present on the test class or
2705+
method.
27062706

27072707
When parallel execution is enabled and a default `{ClassOrderer}` is registered (see
27082708
<<writing-tests-test-execution-order-classes>> for details), top-level test classes will

junit-jupiter-api/src/main/java/org/junit/jupiter/api/TestInstance.java

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.lang.annotation.Target;
2121

2222
import org.apiguardian.api.API;
23+
import org.junit.jupiter.api.parallel.Execution;
2324

2425
/**
2526
* {@code @TestInstance} is a type-level annotation that is used to configure
@@ -59,8 +60,14 @@
5960
* create a custom <em>composed annotation</em> that inherits the semantics
6061
* of {@code @TestInstance}.
6162
*
63+
* <h2>Parallel Execution</h2>
64+
* <p>Using the {@link Lifecycle#PER_CLASS PER_CLASS} lifecycle mode disables
65+
* parallel execution unless the test class or test method is annotated with
66+
* {@link Execution @Execution(CONCURRENT)}.
67+
*
6268
* @since 5.0
6369
* @see Nested @Nested
70+
* @see Execution @Execution
6471
*/
6572
@Target(ElementType.TYPE)
6673
@Retention(RetentionPolicy.RUNTIME)

junit-jupiter-api/src/main/java/org/junit/jupiter/api/TestMethodOrder.java

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.lang.annotation.Target;
2121

2222
import org.apiguardian.api.API;
23+
import org.junit.jupiter.api.parallel.Execution;
2324

2425
/**
2526
* {@code @TestMethodOrder} is a type-level annotation that is used to configure
@@ -64,6 +65,11 @@
6465
* }
6566
* </pre>
6667
*
68+
* <h2>Parallel Execution</h2>
69+
* <p>Using a {@link MethodOrderer} disables parallel execution unless the test
70+
* class or test method is annotated with
71+
* {@link Execution @Execution(CONCURRENT)}.
72+
*
6773
* @since 5.4
6874
* @see MethodOrderer
6975
* @see TestClassOrder

junit-jupiter-api/src/main/java/org/junit/jupiter/api/parallel/Execution.java

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.lang.annotation.Target;
2121

2222
import org.apiguardian.api.API;
23+
import org.junit.jupiter.api.MethodOrderer;
24+
import org.junit.jupiter.api.TestInstance;
2325

2426
/**
2527
* {@code @Execution} is used to configure the parallel execution
@@ -44,6 +46,12 @@
4446
* <p>{@value #DEFAULT_CLASSES_EXECUTION_MODE_PROPERTY_NAME} overrides
4547
* {@value #DEFAULT_EXECUTION_MODE_PROPERTY_NAME} for top-level classes.
4648
*
49+
* <p>The default execution mode is not applied to classes that use the
50+
* {@link TestInstance.Lifecycle#PER_CLASS PER_CLASS} lifecycle or a
51+
* {@link MethodOrderer}. In both cases, test methods in such test classes are
52+
* only executed concurrently if the {@code @Execution(CONCURRENT)} annotation
53+
* is present on the test class or method.
54+
*
4755
* @see Isolated
4856
* @see ResourceLock
4957
* @since 5.3

0 commit comments

Comments
 (0)