Debian Codegraph @

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

raw symbols SCIP
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;
12
13 import static org.apiguardian.api.API.Status.STABLE;
14
15 import java.lang.annotation.Documented;
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 @TestMethodOrder} is a type-level annotation that is used to configure
26 * a {@link #value MethodOrderer} for the <em>test methods</em> of the annotated
27 * test class or test interface.
28 *
29 * <p>In this context, the term "test method" refers to any method annotated with
30 * {@code @Test}, {@code @RepeatedTest}, {@code @ParameterizedTest},
31 * {@code @TestFactory}, or {@code @TestTemplate}.
32 *
33 * <p>If {@code @TestMethodOrder} is not explicitly declared on a test class,
34 * inherited from a parent class, or declared on a test interface implemented by
35 * a test class, test methods will be ordered using a default algorithm that is
36 * deterministic but intentionally nonobvious.
37 *
38 * <p>As an alternative to {@code @TestMethodOrder}, a global {@link MethodOrderer}
39 * can be configured for the entire test suite via the
40 * {@value MethodOrderer#DEFAULT_ORDER_PROPERTY_NAME} configuration parameter. See
41 * the User Guide for details. Note, however, that a {@code @TestClassOrder}
42 * declaration always overrides a global {@code ClassOrderer}.
43 *
44 * <h2>Example Usage</h2>
45 *
46 * <p>The following demonstrates how to guarantee that test methods are executed
47 * in the order specified via the {@link Order @Order} annotation.
48 *
49 * <pre class="code">
50 * {@literal @}TestMethodOrder(MethodOrderer.OrderAnnotation.class)
51 * class OrderedTests {
52 *
53 * {@literal @}Test
54 * {@literal @}Order(1)
55 * void nullValues() {}
56 *
57 * {@literal @}Test
58 * {@literal @}Order(2)
59 * void emptyValues() {}
60 *
61 * {@literal @}Test
62 * {@literal @}Order(3)
63 * void validValues() {}
64 * }
65 * </pre>
66 *
67 * @since 5.4
68 * @see MethodOrderer
69 * @see TestClassOrder
70 */
71 @Target(ElementType.TYPE)
72 @Retention(RetentionPolicy.RUNTIME)
73 @Documented
74 @Inherited
75 @API(status = STABLE, since = "5.7")
76 public @interface TestMethodOrder {
77
78 /**
79 * The {@link MethodOrderer} to use.
80 *
81 * @see MethodOrderer
82 * @see MethodOrderer.MethodName
83 * @see MethodOrderer.DisplayName
84 * @see MethodOrderer.OrderAnnotation
85 * @see MethodOrderer.Random
86 */
87 Class<? extends MethodOrderer> value();
88
89 }