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: