Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/TestTemplate.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.Retention;
18 import java.lang.annotation.RetentionPolicy;
19 import java.lang.annotation.Target;
20
21 import org.apiguardian.api.API;
22 import org.junit.platform.commons.annotation.Testable;
23
24 /**
25 * {@code @TestTemplate} is used to signal that the annotated method is a
26 * <em>test template</em> method.
27 *
28 * <p>In contrast to {@link Test @Test} methods, a test template is not itself
29 * a test case but rather a template for test cases. As such, it is designed to
30 * be invoked multiple times depending on the number of {@linkplain
31 * org.junit.jupiter.api.extension.TestTemplateInvocationContext invocation
32 * contexts} returned by the registered {@linkplain
33 * org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
34 * providers}. Must be used together with at least one provider. Otherwise,
35 * execution will fail.
36 *
37 * <p>Each invocation of a test template method behaves like the execution of
38 * a regular {@link Test @Test} method with full support for the same lifecycle
39 * callbacks and extensions.
40 *
41 * <p>{@code @TestTemplate} methods must not be {@code private} or {@code static}
42 * and must return {@code void}.
43 *
44 * <p>{@code @TestTemplate} methods may optionally declare parameters to be
45 * resolved by {@link org.junit.jupiter.api.extension.ParameterResolver
46 * ParameterResolvers}.
47 *
48 * <p>{@code @TestTemplate} may also be used as a meta-annotation in order to
49 * create a custom <em>composed annotation</em> that inherits the semantics
50 * of {@code @TestTemplate}.
51 *
52 * <h2>Test Execution Order</h2>
53 *
54 * <p>By default, test methods will be ordered using an algorithm that is
55 * deterministic but intentionally nonobvious. This ensures that subsequent runs
56 * of a test suite execute test methods in the same order, thereby allowing for
57 * repeatable builds. In this context, a <em>test method</em> is any instance
58 * method that is directly annotated or meta-annotated with {@code @Test},
59 * {@code @RepeatedTest}, {@code @ParameterizedTest}, {@code @TestFactory}, or
60 * {@code @TestTemplate}.
61 *
62 * <p>Although true <em>unit tests</em> typically should not rely on the order
63 * in which they are executed, there are times when it is necessary to enforce
64 * a specific test method execution order &mdash; for example, when writing
65 * <em>integration tests</em> or <em>functional tests</em> where the sequence of
66 * the tests is important, especially in conjunction with
67 * {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.
68 *
69 * <p>To control the order in which test methods are executed, annotate your
70 * test class or test interface with {@link TestMethodOrder @TestMethodOrder}
71 * and specify the desired {@link MethodOrderer} implementation.
72 *
73 * @since 5.0
74 * @see Test
75 * @see org.junit.jupiter.api.extension.TestTemplateInvocationContext
76 * @see org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
77 */
78 @Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
79 @Retention(RetentionPolicy.RUNTIME)
80 @Documented
81 @API(status = STABLE, since = "5.0")
82 @Testable
83 public @interface TestTemplate {
84 }