Overview
As of Spring Framework 6.2.13 (see #35680), we support JUnit Jupiter's ExtensionContextScope.TEST_METHOD behavior in the SpringExtension and the BeanOverrideTestExecutionListener; however, users can only benefit from that if they explicitly set the junit.jupiter.extensions.testinstantiation.extensioncontextscope.default configuration parameter to test_method for their entire test suite, which may have adverse effects on third-party JUnit Jupiter extensions.
For Spring Framework 7.0, in order to support common @Autowired injection scenarios in @Nested test class hierarchies by default, we should configure the SpringExtension to use ExtensionContextScope.TEST_METHOD, and we should provide a mechanism for users to switch back to the legacy "test-class scoped ExtensionContext" behavior — for example, via a type-level annotation that can be applied to a given @Nested test class hierarchy.
Related Spring Issues
Related JUnit Issues
Overview
As of Spring Framework 6.2.13 (see #35680), we support JUnit Jupiter's
ExtensionContextScope.TEST_METHODbehavior in theSpringExtensionand theBeanOverrideTestExecutionListener; however, users can only benefit from that if they explicitly set thejunit.jupiter.extensions.testinstantiation.extensioncontextscope.defaultconfiguration parameter totest_methodfor their entire test suite, which may have adverse effects on third-party JUnit Jupiter extensions.For Spring Framework 7.0, in order to support common
@Autowiredinjection scenarios in@Nestedtest class hierarchies by default, we should configure theSpringExtensionto useExtensionContextScope.TEST_METHOD, and we should provide a mechanism for users to switch back to the legacy "test-class scopedExtensionContext" behavior — for example, via a type-level annotation that can be applied to a given@Nestedtest class hierarchy.Related Spring Issues
@Nestedwithin test classes with complex inheritance and annotation arrangements #28466@Nestedtest class #34576isAutowirableConstructor(Executable, PropertyProvider)inTestConstructorUtilsand deprecate existing variants #35676TEST_METHODExtensionContextScopeis not fully supported #35680TestContextsemantics #35716SpringExtensionvia Spring or JUnit properties #36460Related JUnit Issues
ExtensionContextin lifecycle callback methods for test executing in@Nestedtest class junit-team/junit-framework#1332ExtensionContextfor test-specific callbacks in extensions junit-team/junit-framework#3445TestInstantiationAwareExtensionand raise awareness of semantic differences junit-team/junit-framework#5107