Skip to content

Commit ac0136b

Browse files
committed
Clarify supported targets for annotations in the TestContext framework
Closes gh-32772
1 parent 3048cfe commit ac0136b

30 files changed

+111
-107
lines changed

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-junit-jupiter.adoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ for further details.
165165
[[integration-testing-annotations-testconstructor]]
166166
== `@TestConstructor`
167167

168-
`@TestConstructor` is a type-level annotation that is used to configure how the parameters
169-
of a test class constructor are autowired from components in the test's
168+
`@TestConstructor` is an annotation that can be applied to a test class to configure how
169+
the parameters of a test class constructor are autowired from components in the test's
170170
`ApplicationContext`.
171171

172172
If `@TestConstructor` is not present or meta-present on a test class, the default _test
@@ -199,9 +199,9 @@ Spring Boot Test.
199199
[[integration-testing-annotations-nestedtestconfiguration]]
200200
== `@NestedTestConfiguration`
201201

202-
`@NestedTestConfiguration` is a type-level annotation that is used to configure how
203-
Spring test configuration annotations are processed within enclosing class hierarchies
204-
for inner test classes.
202+
`@NestedTestConfiguration` is an annotation that can be applied to a test class to
203+
configure how Spring test configuration annotations are processed within enclosing class
204+
hierarchies for inner test classes.
205205

206206
If `@NestedTestConfiguration` is not present or meta-present on a test class, in its
207207
supertype hierarchy, or in its enclosing class hierarchy, the default _enclosing

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-junit4.adoc

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ xref:testing/testcontext-framework/support-classes.adoc#testcontext-junit4-runne
1313
[[integration-testing-annotations-junit4-ifprofilevalue]]
1414
== `@IfProfileValue`
1515

16-
`@IfProfileValue` indicates that the annotated test is enabled for a specific testing
17-
environment. If the configured `ProfileValueSource` returns a matching `value` for the
18-
provided `name`, the test is enabled. Otherwise, the test is disabled and, effectively,
19-
ignored.
16+
`@IfProfileValue` indicates that the annotated test class or test method is enabled for a
17+
specific testing environment. If the configured `ProfileValueSource` returns a matching
18+
`value` for the provided `name`, the test is enabled. Otherwise, the test is disabled
19+
and, effectively, ignored.
2020

2121
You can apply `@IfProfileValue` at the class level, the method level, or both.
2222
Class-level usage of `@IfProfileValue` takes precedence over method-level usage for any
@@ -90,11 +90,12 @@ Kotlin::
9090
[[integration-testing-annotations-junit4-profilevaluesourceconfiguration]]
9191
== `@ProfileValueSourceConfiguration`
9292

93-
`@ProfileValueSourceConfiguration` is a class-level annotation that specifies what type
94-
of `ProfileValueSource` to use when retrieving profile values configured through the
95-
`@IfProfileValue` annotation. If `@ProfileValueSourceConfiguration` is not declared for a
96-
test, `SystemProfileValueSource` is used by default. The following example shows how to
97-
use `@ProfileValueSourceConfiguration`:
93+
`@ProfileValueSourceConfiguration` is an annotation that can be applied to a test class
94+
to specify what type of `ProfileValueSource` to use when retrieving profile values
95+
configured through the `@IfProfileValue` annotation. If
96+
`@ProfileValueSourceConfiguration` is not declared for a test, `SystemProfileValueSource`
97+
is used by default. The following example shows how to use
98+
`@ProfileValueSourceConfiguration`:
9899

99100
[tabs]
100101
======

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-activeprofiles.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[spring-testing-annotation-activeprofiles]]
22
= `@ActiveProfiles`
33

4-
`@ActiveProfiles` is a class-level annotation that is used to declare which bean
5-
definition profiles should be active when loading an `ApplicationContext` for an
4+
`@ActiveProfiles` is an annotation that can be applied to a test class to declare which
5+
bean definition profiles should be active when loading an `ApplicationContext` for an
66
integration test.
77

88
The following example indicates that the `dev` profile should be active:

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-bootstrapwith.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
= `@BootstrapWith`
33
:page-section-summary-toc: 1
44

5-
`@BootstrapWith` is a class-level annotation that you can use to configure how the Spring
6-
TestContext Framework is bootstrapped. Specifically, you can use `@BootstrapWith` to
7-
specify a custom `TestContextBootstrapper`. See the section on
5+
`@BootstrapWith` is an annotation that can be applied to a test class to configure how
6+
the Spring TestContext Framework is bootstrapped. Specifically, you can use
7+
`@BootstrapWith` to specify a custom `TestContextBootstrapper`. See the section on
88
xref:testing/testcontext-framework/bootstrapping.adoc[bootstrapping the TestContext framework] for further details.
99

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-contextconfiguration.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[[spring-testing-annotation-contextconfiguration]]
22
= `@ContextConfiguration`
33

4-
`@ContextConfiguration` defines class-level metadata that is used to determine how to
5-
load and configure an `ApplicationContext` for integration tests. Specifically,
6-
`@ContextConfiguration` declares the application context resource `locations` or the
7-
component `classes` used to load the context.
4+
`@ContextConfiguration` is an annotation that can be applied to a test class to configure
5+
metadata that is used to determine how to load and configure an `ApplicationContext` for
6+
integration tests. Specifically, `@ContextConfiguration` declares the application context
7+
resource `locations` or the component `classes` used to load the context.
88

99
Resource locations are typically XML configuration files or Groovy scripts located in the
1010
classpath, while component classes are typically `@Configuration` classes. However,

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-contextcustomizerfactories.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[[spring-testing-annotation-contextcustomizerfactories]]
22
= `@ContextCustomizerFactories`
33

4-
`@ContextCustomizerFactories` is used to register `ContextCustomizerFactory`
5-
implementations for a particular test class, its subclasses, and its nested classes. If
6-
you wish to register a factory globally, you should register it via the automatic
7-
discovery mechanism described in
4+
`@ContextCustomizerFactories` is an annotation that can be applied to a test class to
5+
register `ContextCustomizerFactory` implementations for the particular test class, its
6+
subclasses, and its nested classes. If you wish to register a factory globally, you
7+
should register it via the automatic discovery mechanism described in
88
xref:testing/testcontext-framework/ctx-management/context-customizers.adoc[`ContextCustomizerFactory` Configuration].
99

1010
The following example shows how to register two `ContextCustomizerFactory` implementations:

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-contexthierarchy.adoc

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[[spring-testing-annotation-contexthierarchy]]
22
= `@ContextHierarchy`
33

4-
`@ContextHierarchy` is a class-level annotation that is used to define a hierarchy of
5-
`ApplicationContext` instances for integration tests. `@ContextHierarchy` should be
6-
declared with a list of one or more `@ContextConfiguration` instances, each of which
7-
defines a level in the context hierarchy. The following examples demonstrate the use of
8-
`@ContextHierarchy` within a single test class (`@ContextHierarchy` can also be used
9-
within a test class hierarchy):
4+
`@ContextHierarchy` is an annotation that can be applied to a test class to define a
5+
hierarchy of `ApplicationContext` instances for integration tests. `@ContextHierarchy`
6+
should be declared with a list of one or more `@ContextConfiguration` instances, each of
7+
which defines a level in the context hierarchy. The following examples demonstrate the
8+
use of `@ContextHierarchy` within a single test class (`@ContextHierarchy` can also be
9+
used within a test class hierarchy):
1010

1111
[tabs]
1212
======

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-dirtiescontext.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ rebuilt for any subsequent test that requires a context with the same configurat
1010
metadata.
1111

1212
You can use `@DirtiesContext` as both a class-level and a method-level annotation within
13-
the same class or class hierarchy. In such scenarios, the `ApplicationContext` is marked
14-
as dirty before or after any such annotated method as well as before or after the current
15-
test class, depending on the configured `methodMode` and `classMode`. When
13+
the same test class or test class hierarchy. In such scenarios, the `ApplicationContext`
14+
is marked as dirty before or after any such annotated method as well as before or after
15+
the current test class, depending on the configured `methodMode` and `classMode`. When
1616
`@DirtiesContext` is declared at both the class level and the method level, the
1717
configured modes from both annotations will be honored. For example, if the class mode is
1818
set to `BEFORE_EACH_TEST_METHOD` and the method mode is set to `AFTER_METHOD`, the

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-disabledinaotmode.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[spring-testing-annotation-disabledinaotmode]]
22
= `@DisabledInAotMode`
33

4-
`@DisabledInAotMode` signals that an annotated test class is disabled in Spring AOT
4+
`@DisabledInAotMode` signals that the annotated test class is disabled in Spring AOT
55
(ahead-of-time) mode, which means that the `ApplicationContext` for the test class will
66
not be processed for AOT optimizations at build time.
77

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-dynamicpropertysource.adoc

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[[spring-testing-annotation-dynamicpropertysource]]
22
= `@DynamicPropertySource`
33

4-
`@DynamicPropertySource` is a method-level annotation that you can use to register
5-
_dynamic_ properties to be added to the set of `PropertySources` in the `Environment` for
6-
an `ApplicationContext` loaded for an integration test. Dynamic properties are useful
7-
when you do not know the value of the properties upfront – for example, if the properties
8-
are managed by an external resource such as for a container managed by the
9-
{testcontainers-site}[Testcontainers] project.
4+
`@DynamicPropertySource` is an annotation that can be applied to methods in integration
5+
test classes that need to register _dynamic_ properties to be added to the set of
6+
`PropertySources` in the `Environment` for an `ApplicationContext` loaded for an
7+
integration test. Dynamic properties are useful when you do not know the value of the
8+
properties upfront – for example, if the properties are managed by an external resource
9+
such as for a container managed by the {testcontainers-site}[Testcontainers] project.
1010

1111
The following example demonstrates how to register a dynamic property:
1212

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-recordapplicationevents.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
= `@RecordApplicationEvents`
33
:page-section-summary-toc: 1
44

5-
`@RecordApplicationEvents` is a class-level annotation that is used to instruct the
6-
_Spring TestContext Framework_ to record all application events that are published in the
7-
`ApplicationContext` during the execution of a single test.
5+
`@RecordApplicationEvents` is an annotation that can be applied to a test class to
6+
instruct the _Spring TestContext Framework_ to record all application events that are
7+
published in the `ApplicationContext` during the execution of a single test.
88

99
The recorded events can be accessed via the `ApplicationEvents` API within tests.
1010

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testexecutionlisteners.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[spring-testing-annotation-testexecutionlisteners]]
22
= `@TestExecutionListeners`
33

4-
`@TestExecutionListeners` is used to register listeners for a particular test class, its
4+
`@TestExecutionListeners` is used to register listeners for the annotated test class, its
55
subclasses, and its nested classes. If you wish to register a listener globally, you
66
should register it via the automatic discovery mechanism described in
77
xref:testing/testcontext-framework/tel-config.adoc[`TestExecutionListener` Configuration].

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-testpropertysource.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[spring-testing-annotation-testpropertysource]]
22
= `@TestPropertySource`
33

4-
`@TestPropertySource` is a class-level annotation that you can use to configure the
5-
locations of properties files and inlined properties to be added to the set of
4+
`@TestPropertySource` is an annotation that can be applied to a test class to configure
5+
the locations of properties files and inlined properties to be added to the set of
66
`PropertySources` in the `Environment` for an `ApplicationContext` loaded for an
77
integration test.
88

Diff for: framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-webappconfiguration.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[[spring-testing-annotation-webappconfiguration]]
22
= `@WebAppConfiguration`
33

4-
`@WebAppConfiguration` is a class-level annotation that you can use to declare that the
5-
`ApplicationContext` loaded for an integration test should be a `WebApplicationContext`.
6-
The mere presence of `@WebAppConfiguration` on a test class ensures that a
7-
`WebApplicationContext` is loaded for the test, using the default value of
4+
`@WebAppConfiguration` is an annotation that can be applied to a test class to declare
5+
that the `ApplicationContext` loaded for an integration test should be a
6+
`WebApplicationContext`. The mere presence of `@WebAppConfiguration` on a test class
7+
ensures that a `WebApplicationContext` is loaded for the test, using the default value of
88
`"file:src/main/webapp"` for the path to the root of the web application (that is, the
99
resource base path). The resource base path is used behind the scenes to create a
1010
`MockServletContext`, which serves as the `ServletContext` for the test's

Diff for: spring-test/src/main/java/org/springframework/test/annotation/DirtiesContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* will be supplied a new context.
3636
*
3737
* <p>{@code @DirtiesContext} may be used as a class-level and method-level
38-
* annotation within the same class or class hierarchy. In such scenarios, the
39-
* {@code ApplicationContext} will be marked as <em>dirty</em> before or
38+
* annotation within the same test class or test class hierarchy. In such scenarios,
39+
* the {@code ApplicationContext} will be marked as <em>dirty</em> before or
4040
* after any such annotated method as well as before or after the current test
4141
* class, depending on the configured {@link #methodMode} and {@link #classMode}.
4242
* When {@code @DirtiesContext} is declared at both the class level and the

Diff for: spring-test/src/main/java/org/springframework/test/annotation/IfProfileValue.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -24,8 +24,8 @@
2424
import java.lang.annotation.Target;
2525

2626
/**
27-
* Test annotation for use with JUnit 4 to indicate whether a test is enabled or
28-
* disabled for a specific testing profile.
27+
* Test annotation for use with JUnit 4 to indicate whether the annotated test
28+
* class or test method is enabled or disabled for a specific testing profile.
2929
*
3030
* <p>In the context of this annotation, the term <em>profile</em> refers to
3131
* a Java system property by default; however, the semantics can be changed

Diff for: spring-test/src/main/java/org/springframework/test/annotation/ProfileValueSourceConfiguration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -24,8 +24,8 @@
2424
import java.lang.annotation.Target;
2525

2626
/**
27-
* {@code ProfileValueSourceConfiguration} is a class-level annotation for use
28-
* with JUnit 4 which is used to specify what type of {@link ProfileValueSource}
27+
* {@code ProfileValueSourceConfiguration} is an annotation that can be applied
28+
* to a JUnit 4 based test class to specify what type of {@link ProfileValueSource}
2929
* to use when retrieving <em>profile values</em> configured via
3030
* {@link IfProfileValue @IfProfileValue}.
3131
*

Diff for: spring-test/src/main/java/org/springframework/test/context/ActiveProfiles.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -26,10 +26,10 @@
2626
import org.springframework.core.annotation.AliasFor;
2727

2828
/**
29-
* {@code ActiveProfiles} is a class-level annotation that is used to declare
30-
* which <em>active bean definition profiles</em> should be used when loading
31-
* an {@link org.springframework.context.ApplicationContext ApplicationContext}
32-
* for test classes.
29+
* {@code ActiveProfiles} is an annotation that can be applied to a test class
30+
* to declare which <em>active bean definition profiles</em> should be used when
31+
* loading an {@link org.springframework.context.ApplicationContext ApplicationContext}
32+
* for integration tests.
3333
*
3434
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
3535
* <em>composed annotations</em>.

Diff for: spring-test/src/main/java/org/springframework/test/context/BootstrapWith.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -24,8 +24,9 @@
2424
import java.lang.annotation.Target;
2525

2626
/**
27-
* {@code @BootstrapWith} defines class-level metadata that is used to determine
28-
* how to bootstrap the <em>Spring TestContext Framework</em>.
27+
* {@code @BootstrapWith} is an annotation that can be applied to a test class
28+
* to define metadata that is used to determine how to bootstrap the
29+
* <em>Spring TestContext Framework</em>.
2930
*
3031
* <p>This annotation may also be used as a <em>meta-annotation</em> to create
3132
* custom <em>composed annotations</em>. As of Spring Framework 5.1, a locally

Diff for: spring-test/src/main/java/org/springframework/test/context/ContextConfiguration.java

+5-4
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.
@@ -28,9 +28,10 @@
2828
import org.springframework.core.annotation.AliasFor;
2929

3030
/**
31-
* {@code @ContextConfiguration} defines class-level metadata that is used to determine
32-
* how to load and configure an {@link org.springframework.context.ApplicationContext
33-
* ApplicationContext} for integration tests.
31+
* {@code @ContextConfiguration} is an annotation that can be applied to a test
32+
* class to define metadata that is used to determine how to load and configure
33+
* an {@link org.springframework.context.ApplicationContext ApplicationContext}
34+
* for integration tests.
3435
*
3536
* <h3>Supported Resource Types</h3>
3637
*

Diff for: spring-test/src/main/java/org/springframework/test/context/ContextCustomizerFactories.java

+4-4
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.
@@ -26,9 +26,9 @@
2626
import org.springframework.core.annotation.AliasFor;
2727

2828
/**
29-
* {@code @ContextCustomizerFactories} defines class-level metadata for configuring
30-
* which {@link ContextCustomizerFactory} implementations should be registered with
31-
* the <em>Spring TestContext Framework</em>.
29+
* {@code @ContextCustomizerFactories} is an annotation that can be applied to a
30+
* test class to configure which {@link ContextCustomizerFactory} implementations
31+
* should be registered with the <em>Spring TestContext Framework</em>.
3232
*
3333
* <p>{@code @ContextCustomizerFactories} is used to register factories for a
3434
* particular test class, its subclasses, and its nested classes. If you wish to

Diff for: spring-test/src/main/java/org/springframework/test/context/ContextHierarchy.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -24,8 +24,8 @@
2424
import java.lang.annotation.Target;
2525

2626
/**
27-
* {@code @ContextHierarchy} is a class-level annotation that is used to define
28-
* a hierarchy of {@link org.springframework.context.ApplicationContext
27+
* {@code @ContextHierarchy} is an annotation that can be applied to a test class
28+
* to define a hierarchy of {@link org.springframework.context.ApplicationContext
2929
* ApplicationContexts} for integration tests.
3030
*
3131
* <h3>Examples</h3>

Diff for: spring-test/src/main/java/org/springframework/test/context/DynamicPropertySource.java

+4-3
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.
@@ -23,8 +23,9 @@
2323
import java.lang.annotation.Target;
2424

2525
/**
26-
* Method-level annotation for integration tests that need to add properties with
27-
* dynamic values to the {@code Environment}'s set of {@code PropertySources}.
26+
* {@code @DynamicPropertySource} is an annotation that can be applied to methods
27+
* in integration test classes that need to add properties with dynamic values to
28+
* the {@code Environment}'s set of {@code PropertySources}.
2829
*
2930
* <p>This annotation and its supporting infrastructure were originally designed
3031
* to allow properties from

0 commit comments

Comments
 (0)