Skip to content

Commit b4ba1bf

Browse files
2897robomarcphilipp
andcommitted
Add example for using @Execution annotation to User Guide (#4525)
Resolves #2669. --------- Co-authored-by: Marc Philipp <mail@marcphilipp.de>
1 parent 2bd8bd9 commit b4ba1bf

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
@@ -3195,6 +3195,17 @@ execution order. Thus, in both cases, test methods in such test classes are only
31953195
concurrently if the `@Execution(CONCURRENT)` annotation is present on the test class or
31963196
method.
31973197

3198+
You can use the `@Execution` annotation to explicitly configure the execution mode for a
3199+
test class or method:
3200+
3201+
[source,java]
3202+
----
3203+
include::{testDir}/example/ExplicitExecutionModeDemo.java[]
3204+
----
3205+
3206+
This allows test classes or methods to opt in or out of concurrent execution regardless of
3207+
the globally configured default.
3208+
31983209
When parallel execution is enabled and a default `{ClassOrderer}` is registered (see
31993210
<<writing-tests-test-execution-order-classes>> for details), top-level test classes will
32003211
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)