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: