| 1 | /* |
| 2 | * Copyright 2015-2024 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 org.junit.jupiter.api.parallel; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.EXPERIMENTAL; |
| 14 | import static org.apiguardian.api.API.Status.STABLE; |
| 15 | |
| 16 | import java.lang.annotation.ElementType; |
| 17 | import java.lang.annotation.Inherited; |
| 18 | import java.lang.annotation.Retention; |
| 19 | import java.lang.annotation.RetentionPolicy; |
| 20 | import java.lang.annotation.Target; |
| 21 | |
| 22 | import org.apiguardian.api.API; |
| 23 | |
| 24 | /** |
| 25 | * {@code @Execution} is used to configure the parallel execution |
| 26 | * {@linkplain #value mode} of a test class or test method. |
| 27 | * |
| 28 | * <p>Since JUnit Jupiter 5.4, this annotation is {@linkplain Inherited inherited} |
| 29 | * within class hierarchies. |
| 30 | * |
| 31 | * <h2>Default Execution Mode</h2> |
| 32 | * |
| 33 | * <p>If this annotation is not present, {@link ExecutionMode#SAME_THREAD} is |
| 34 | * used unless a default execution mode is defined via one of the following |
| 35 | * configuration parameters: |
| 36 | * |
| 37 | * <dl> |
| 38 | * <dt>{@value #DEFAULT_EXECUTION_MODE_PROPERTY_NAME}</dt> |
| 39 | * <dd>Default execution mode for all classes and tests</dd> |
| 40 | * <dt>{@value #DEFAULT_CLASSES_EXECUTION_MODE_PROPERTY_NAME}</dt> |
| 41 | * <dd>Default execution mode for top-level classes</dd> |
| 42 | * </dl> |
| 43 | * |
| 44 | * <p>{@value #DEFAULT_CLASSES_EXECUTION_MODE_PROPERTY_NAME} overrides |
| 45 | * {@value #DEFAULT_EXECUTION_MODE_PROPERTY_NAME} for top-level classes. |
| 46 | * |
| 47 | * @see Isolated |
| 48 | * @see ResourceLock |
| 49 | * @since 5.3 |
| 50 | */ |
| 51 | @API(status = STABLE, since = "5.10") |
| 52 | @Retention(RetentionPolicy.RUNTIME) |
| 53 | @Target({ ElementType.TYPE, ElementType.METHOD }) |
| 54 | @Inherited |
| 55 | public @interface Execution { |
| 56 | |
| 57 | /** |
| 58 | * Property name used to set the default test execution mode: {@value} |
| 59 | * |
| 60 | * <p>This setting is only effective if parallel execution is enabled. |
| 61 | * |
| 62 | * <h4>Supported Values</h4> |
| 63 | * |
| 64 | * <p>Supported values include names of enum constants defined in |
| 65 | * {@link ExecutionMode}, ignoring case. |
| 66 | * |
| 67 | * <p>If not specified, the default is "same_thread" which corresponds to |
| 68 | * {@code @Execution(ExecutionMode.SAME_THREAD)}. |
| 69 | * |
| 70 | * @since 5.4 |
| 71 | */ |
| 72 | @API(status = EXPERIMENTAL, since = "5.9") |
| 73 | String DEFAULT_EXECUTION_MODE_PROPERTY_NAME = "junit.jupiter.execution.parallel.mode.default"; |
| 74 | |
| 75 | /** |
| 76 | * Property name used to set the default test execution mode for top-level |
| 77 | * classes: {@value} |
| 78 | * |
| 79 | * <p>This setting is only effective if parallel execution is enabled. |
| 80 | * |
| 81 | * <h4>Supported Values</h4> |
| 82 | * |
| 83 | * <p>Supported values include names of enum constants defined in |
| 84 | * {@link ExecutionMode}, ignoring case. |
| 85 | * |
| 86 | * <p>If not specified, it will be resolved into the same value as |
| 87 | * {@link #DEFAULT_EXECUTION_MODE_PROPERTY_NAME}. |
| 88 | * |
| 89 | * @since 5.4 |
| 90 | */ |
| 91 | @API(status = EXPERIMENTAL, since = "5.9") |
| 92 | String DEFAULT_CLASSES_EXECUTION_MODE_PROPERTY_NAME = "junit.jupiter.execution.parallel.mode.classes.default"; |
| 93 | |
| 94 | /** |
| 95 | * The required/preferred execution mode. |
| 96 | * |
| 97 | * @see ExecutionMode |
| 98 | */ |
| 99 | ExecutionMode value(); |
| 100 | |
| 101 | /** |
| 102 | * The reason for using the selected execution mode. |
| 103 | * |
| 104 | * <p>This is for informational purposes only. |
| 105 | * |
| 106 | * @since 5.10 |
| 107 | */ |
| 108 | @API(status = STABLE, since = "5.10") |
| 109 | String reason() default ""; |
| 110 | |
| 111 | } |