Skip to content

Commit 4b94ce4

Browse files
Add example for using @Execution annotation to User Guide (#4525)
Resolves #2669. --------- Co-authored-by: Marc Philipp <[email protected]>
1 parent 145af95 commit 4b94ce4

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,6 +3207,17 @@ execution order. Thus, in both cases, test methods in such test classes are only
32073207
concurrently if the `@Execution(CONCURRENT)` annotation is present on the test class or
32083208
method.
32093209

3210+
You can use the `@Execution` annotation to explicitly configure the execution mode for a
3211+
test class or method:
3212+
3213+
[source,java]
3214+
----
3215+
include::{testDir}/example/ExplicitExecutionModeDemo.java[]
3216+
----
3217+
3218+
This allows test classes or methods to opt in or out of concurrent execution regardless of
3219+
the globally configured default.
3220+
32103221
When parallel execution is enabled and a default `{ClassOrderer}` is registered (see
32113222
<<writing-tests-test-execution-order-classes>> for details), top-level test classes will
32123223
initially be sorted accordingly and scheduled in that order. However, they are not
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2015-2025 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package example;
12+
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.parallel.Execution;
15+
import org.junit.jupiter.api.parallel.ExecutionMode;
16+
17+
@Execution(ExecutionMode.CONCURRENT)
18+
class ExplicitExecutionModeDemo {
19+
20+
@Test
21+
void testA() {
22+
// concurrent
23+
}
24+
25+
@Test
26+
@Execution(ExecutionMode.SAME_THREAD)
27+
void testB() {
28+
// overrides to same_thread
29+
}
30+
}

0 commit comments

Comments
 (0)