| 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.jupiter.api.TestInstance.Lifecycle; |
| 23 | |
| 24 | /** |
| 25 | * {@code @Nested} is used to signal that the annotated class is a nested, |
| 26 | * non-static test class (i.e., an <em>inner class</em>) that can share |
| 27 | * setup and state with an instance of its {@linkplain Class#getEnclosingClass() |
| 28 | * enclosing class}. The enclosing class may be a top-level test class or |
| 29 | * another {@code @Nested} test class, and nesting can be arbitrarily deep. |
| 30 | * |
| 31 | * <p>{@code @Nested} test classes may be ordered via |
| 32 | * {@link TestClassOrder @TestClassOrder} or a global {@link ClassOrderer}. |
| 33 | * |
| 34 | * <h2>Test Instance Lifecycle</h2> |
| 35 | * |
| 36 | * <ul> |
| 37 | * <li>A {@code @Nested} test class <em>can</em> be configured with its own |
| 38 | * {@link Lifecycle} mode which may differ from that of an enclosing test |
| 39 | * class.</li> |
| 40 | * <li>A {@code @Nested} test class <em>cannot</em> change the {@link Lifecycle} |
| 41 | * mode of an enclosing test class.</li> |
| 42 | * </ul> |
| 43 | * |
| 44 | * @since 5.0 |
| 45 | * @see Test |
| 46 | * @see TestInstance |
| 47 | * @see TestClassOrder |
| 48 | */ |
| 49 | @Target(ElementType.TYPE) |
| 50 | @Retention(RetentionPolicy.RUNTIME) |
| 51 | @Documented |
| 52 | @API(status = STABLE, since = "5.0") |
| 53 | public @interface Nested { |
| 54 | } |