Skip to content

Commit 6a9b5d2

Browse files
committed
Document that TestContextAnnotationUtils is required for @⁠Nested support
Closes gh-33586
1 parent f7aa440 commit 6a9b5d2

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

framework-docs/modules/ROOT/pages/testing/testcontext-framework/support-classes.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ any of its subclasses and nested classes. Thus, you may annotate a top-level tes
542542
with `@NestedTestConfiguration`, and that will apply to all of its nested test classes
543543
recursively.
544544

545+
[TIP]
546+
====
547+
If you are developing a component that integrates with the Spring TestContext Framework
548+
and needs to support annotation inheritance within enclosing class hierarchies, you must
549+
use the annotation search utilities provided in `TestContextAnnotationUtils` in order to
550+
honor `@NestedTestConfiguration` semantics.
551+
====
552+
545553
In order to allow development teams to change the default to `OVERRIDE` – for example,
546554
for compatibility with Spring Framework 5.0 through 5.2 – the default mode can be changed
547555
globally via a JVM system property or a `spring.properties` file in the root of the

spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@
5858
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
5959
* <em>composed annotations</em>.
6060
*
61-
* <p>As of Spring Framework 5.3, the use of this annotation typically only makes
62-
* sense in conjunction with {@link org.junit.jupiter.api.Nested @Nested} test
63-
* classes in JUnit Jupiter; however, there may be other testing frameworks with
64-
* support for nested test classes that could also make use of this annotation.
61+
* <p>The use of this annotation typically only makes sense in conjunction with
62+
* {@link org.junit.jupiter.api.Nested @Nested} test classes in JUnit Jupiter;
63+
* however, there may be other testing frameworks with support for nested test
64+
* classes that could also make use of this annotation.
65+
*
66+
* <p>If you are developing a component that integrates with the Spring TestContext
67+
* Framework and needs to support annotation inheritance within enclosing class
68+
* hierarchies, you must use the annotation search utilities provided in
69+
* {@link TestContextAnnotationUtils} in order to honor
70+
* {@code @NestedTestConfiguration} semantics.
6571
*
6672
* <h3>Supported Annotations</h3>
6773
* <p>The <em>Spring TestContext Framework</em> honors {@code @NestedTestConfiguration}
@@ -89,6 +95,7 @@
8995
* @since 5.3
9096
* @see EnclosingConfiguration#INHERIT
9197
* @see EnclosingConfiguration#OVERRIDE
98+
* @see TestContextAnnotationUtils
9299
*/
93100
@Target(ElementType.TYPE)
94101
@Retention(RetentionPolicy.RUNTIME)

spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,8 @@
4747
* and {@link AnnotatedElementUtils}, while transparently honoring
4848
* {@link NestedTestConfiguration @NestedTestConfiguration} semantics.
4949
*
50-
* <p>Mainly for internal use within the <em>Spring TestContext Framework</em>.
50+
* <p>Mainly for internal use within the <em>Spring TestContext Framework</em>
51+
* but also supported for third-party integrations with the TestContext framework.
5152
*
5253
* <p>Whereas {@code AnnotationUtils} and {@code AnnotatedElementUtils} provide
5354
* utilities for <em>getting</em> or <em>finding</em> annotations,
@@ -70,6 +71,7 @@
7071
* @see AnnotationUtils
7172
* @see AnnotatedElementUtils
7273
* @see AnnotationDescriptor
74+
* @see NestedTestConfiguration
7375
*/
7476
public abstract class TestContextAnnotationUtils {
7577

0 commit comments

Comments
 (0)