Closed
Description
Sam Brannen opened SPR-15366 and commented
Status Quo
Spring's support for JUnit Jupiter already supports detection of test configuration (e.g., (@ContextConfiguration
) on @Nested
classes.
However, if a @Nested
class does not declare its own test configuration, Spring will not find the configuration from the enclosing class.
See also this discussion on Stack Overflow regarding nested test classes and @Transactional
.
Proposal
Inspired by issue 8 from the spring-test-junit5
project, it would perhaps be desirable if the Spring TestContext Framework would discover test configuration on an enclosing class for a @Nested
test class.
Deliverables
- Introduce
@NestedTestConfiguration
withEnclosingConfiguration
enum supportingINHERITED
andOVERRIDE
modes. - Make the default
EnclosingConfiguration
mode globally configurable viaSpringProperties
- Switch the default
EnclosingConfiguration
mode toINHERITED
-
@ContextConfiguration
/@ContextHierarchy
-
@ActiveProfiles
-
@TestPropertySource
/@TestPropertySources
-
@WebAppConfiguration
-
@TestConstructor
-
@BootstrapWith
-
@TestExecutionListeners
-
@DirtiesContext
-
@Transactional
-
@Rollback
/@Commit
- ❌
@Sql
/@SqlConfig
/@SqlGroup
- ❌ Document
@NestedTestConfiguration
support in the reference manual - ❌ Document
@NestedTestConfiguration
support and the switching of the default mode toINHERITED
in the upgrade notes in the wiki
Affects: 5.0
Issue Links:
- Support nested test classes with SpringClassRule & SpringMethodRule [SPR-14150] #18722 Support nested test classes with SpringClassRule & SpringMethodRule
- JUnit Jupiter @Nested class cannot share enclosing class's ApplicationContext if nested class is deemed to be a configuration candidate [SPR-16595] #21136 JUnit Jupiter
@Nested
class cannot share enclosing class's ApplicationContext if nested class is deemed to be a configuration candidate
6 votes, 10 watchers