Skip to content

Use test-method scoped ExtensionContext in the SpringExtension #35697

@sbrannen

Description

@sbrannen

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions