Class SpringExtension

java.lang.Object
org.springframework.test.context.junit.jupiter.SpringExtension
All Implemented Interfaces:
AfterAllCallback, AfterEachCallback, AfterTestExecutionCallback, BeforeAllCallback, BeforeEachCallback, BeforeTestExecutionCallback, Extension, ParameterResolver, TestInstancePostProcessor, TestInstantiationAwareExtension

SpringExtension integrates the Spring TestContext Framework into the JUnit Jupiter testing framework.

To use this extension, annotate a JUnit Jupiter based test class with @ExtendWith(SpringExtension.class), @SpringJUnitConfig, @SpringJUnitWebConfig, or any other annotation that is meta-annotated with @ExtendWith(SpringExtension.class) such as @SpringBootTest, etc.

As of Spring Framework 7.0, the SpringExtension is configured to use a test-method scoped ExtensionContext, which enables consistent dependency injection into fields and constructors from the ApplicationContext for the current test method in a @Nested test class hierarchy. However, if a third-party TestExecutionListener is not compatible with the semantics associated with a test-method scoped extension context — or if a developer wishes to switch to test-class scoped semantics — the SpringExtension can be configured to use a test-class scoped extension context by annotating a top-level test class with @SpringExtensionConfig(useTestClassScopedExtensionContext = true).

Since:
5.0
Author:
Sam Brannen, Simon Baslé
See Also: