Annotation Interface NestedTestConfiguration
@NestedTestConfiguration is an annotation that can be applied to a test
class to configure how Spring test configuration annotations are processed
within enclosing class hierarchies (i.e., for inner test classes).
If @NestedTestConfiguration is not present or
meta-present on a test class, in its supertype hierarchy, or in its
enclosing class hierarchy, the default enclosing configuration inheritance
mode will be used. A @NestedTestConfiguration declaration on an
enclosing class for a nested interface will be ignored when searching for the
annotation on classes that implement the interface. See
ENCLOSING_CONFIGURATION_PROPERTY_NAME for details on how to change
the default mode.
When the INHERIT mode is in use,
configuration from an enclosing test class will be inherited by inner test
classes, analogous to the semantics within a test class inheritance hierarchy.
When the OVERRIDE mode is in use,
inner test classes will have to declare their own Spring test configuration
annotations. If you wish to explicitly configure the mode, annotate either
the inner test class or one of its enclosing classes with
@NestedTestConfiguration(...). Note that a
@NestedTestConfiguration(...) declaration is inherited within the
superclass hierarchy as well as within the enclosing class hierarchy. Thus,
there is no need to redeclare the annotation unless you wish to switch the
mode.
This annotation may be used as a meta-annotation to create custom composed annotations.
The use of this annotation typically only makes sense in conjunction with
@Nested test classes in JUnit Jupiter;
however, there may be other testing frameworks with support for nested test
classes that could also make use of this annotation.
If you are developing a component that integrates with the Spring TestContext
Framework and needs to support annotation inheritance within enclosing class
hierarchies, you must use the annotation search utilities provided in
TestContextAnnotationUtils in order to honor
@NestedTestConfiguration semantics.
Supported Annotations
The Spring TestContext Framework honors @NestedTestConfiguration
semantics for the following annotations.
@BootstrapWith@TestExecutionListeners@ContextCustomizerFactories@ContextConfiguration@ContextHierarchy@WebAppConfiguration@ActiveProfiles@TestPropertySource@DynamicPropertySource@TestBean@MockitoBean@MockitoSpyBean@DirtiesContext@Transactional@Rollback@Commit@Sql@SqlConfig@SqlMergeMode@TestConstructor
- Since:
- 5.3
- Author:
- Sam Brannen
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of modes that dictate how test configuration from enclosing classes is processed for inner test classes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringJVM system property used to change the default enclosing configuration inheritance mode: "spring.test.enclosing.configuration". -
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionConfigures theNestedTestConfiguration.EnclosingConfigurationmode.
-
Field Details
-
ENCLOSING_CONFIGURATION_PROPERTY_NAME
JVM system property used to change the default enclosing configuration inheritance mode: "spring.test.enclosing.configuration".Supported values include enum constants defined in
NestedTestConfiguration.EnclosingConfiguration, ignoring case. For example, the default may be changed toNestedTestConfiguration.EnclosingConfiguration.OVERRIDEby supplying the following JVM system property via the command line.-Dspring.test.enclosing.configuration=override
If the property is not set to
OVERRIDE, test configuration for an inner test class will be inherited according toNestedTestConfiguration.EnclosingConfiguration.INHERITsemantics by default.May alternatively be configured via the
SpringPropertiesmechanism.- See Also:
-
-
Element Details
-
value
Configures theNestedTestConfiguration.EnclosingConfigurationmode.- See Also:
-