Skip to content

Use test-method scoped ExtensionContext in the SpringExtension #35697

Closed

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

Activity

  1. added this to the 7.0.0 milestone on Oct 28, 2025
  2. self-assigned this
    on Oct 28, 2025
  3. sbrannen commented on Oct 28, 2025

    @sbrannen
    Author
  4. changed the title [-]Use `TEST_METHOD` `ExtensionContextScope` in `SpringExtension` by default[/-] [+]Use test-method scoped `ExtensionContext` in the `SpringExtension`[/+] on Oct 30, 2025
  5. added 2 commits that reference this issue on Oct 30, 2025
    41ae13d
    d33f2c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址