diff --git a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc index 4f6540554149..0c4f39c92816 100644 --- a/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc +++ b/documentation/src/docs/asciidoc/user-guide/writing-tests.adoc @@ -3195,6 +3195,17 @@ execution order. Thus, in both cases, test methods in such test classes are only concurrently if the `@Execution(CONCURRENT)` annotation is present on the test class or method. +You can use the `@Execution` annotation to explicitly configure the execution mode for a +test class or method: + +[source,java] +---- +include::{testDir}/example/ExplicitExecutionModeDemo.java[] +---- + +This allows test classes or methods to opt in or out of concurrent execution regardless of +the globally configured default. + When parallel execution is enabled and a default `{ClassOrderer}` is registered (see <> for details), top-level test classes will initially be sorted accordingly and scheduled in that order. However, they are not diff --git a/documentation/src/test/java/example/ExplicitExecutionModeDemo.java b/documentation/src/test/java/example/ExplicitExecutionModeDemo.java new file mode 100644 index 000000000000..83735b7b8419 --- /dev/null +++ b/documentation/src/test/java/example/ExplicitExecutionModeDemo.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015-2025 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package example; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; + +@Execution(ExecutionMode.CONCURRENT) +class ExplicitExecutionModeDemo { + + @Test + void testA() { + // concurrent + } + + @Test + @Execution(ExecutionMode.SAME_THREAD) + void testB() { + // overrides to same_thread + } +}