spring-framework / org.springframework.test.context.junit.jupiter / SpringExtension

SpringExtension

open class SpringExtension : BeforeAllCallback, AfterAllCallback, TestInstancePostProcessor, BeforeEachCallback, AfterEachCallback, BeforeTestExecutionCallback, AfterTestExecutionCallback, ParameterResolver

SpringExtension integrates the Spring TestContext Framework into JUnit 5's Jupiter programming model.

To use this extension, simply annotate a JUnit Jupiter based test class with @ExtendWith(SpringExtension.class), @SpringJUnitConfig, or @SpringJUnitWebConfig.

Author
Sam Brannen

Since
5.0

See Also
org.springframework.test.context.junit.jupiter.EnabledIforg.springframework.test.context.junit.jupiter.DisabledIforg.springframework.test.context.junit.jupiter.SpringJUnitConfigorg.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfigorg.springframework.test.context.TestContextManager

Constructors

<init>

SpringExtension()

SpringExtension integrates the Spring TestContext Framework into JUnit 5's Jupiter programming model.

To use this extension, simply annotate a JUnit Jupiter based test class with @ExtendWith(SpringExtension.class), @SpringJUnitConfig, or @SpringJUnitWebConfig.

Functions

afterAll

open fun afterAll(context: ExtensionContext): Unit

Delegates to TestContextManager#afterTestClass.

afterEach

open fun afterEach(context: ExtensionContext): Unit

Delegates to TestContextManager#afterTestMethod.

afterTestExecution

open fun afterTestExecution(context: ExtensionContext): Unit

Delegates to TestContextManager#afterTestExecution.

beforeAll

open fun beforeAll(context: ExtensionContext): Unit

Delegates to TestContextManager#beforeTestClass.

beforeEach

open fun beforeEach(context: ExtensionContext): Unit

Delegates to TestContextManager#beforeTestMethod.

beforeTestExecution

open fun beforeTestExecution(context: ExtensionContext): Unit

Delegates to TestContextManager#beforeTestExecution.

getApplicationContext

open static fun getApplicationContext(context: ExtensionContext): ApplicationContext

Get the ApplicationContext associated with the supplied ExtensionContext.

postProcessTestInstance

open fun postProcessTestInstance(testInstance: Any, context: ExtensionContext): Unit

Delegates to TestContextManager#prepareTestInstance.

resolveParameter

open fun resolveParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Any

Resolve a value for the Parameter in the supplied ParameterContext by retrieving the corresponding dependency from the test's ApplicationContext.

Delegates to ParameterAutowireUtils#resolveDependency.

supportsParameter

open fun supportsParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Boolean

Determine if the value for the Parameter in the supplied ParameterContext should be autowired from the test's ApplicationContext.

Returns true if the parameter is declared in a Constructor that is annotated with Autowired and otherwise delegates to ParameterAutowireUtils#isAutowirable.

WARNING: If the parameter is declared in a Constructor that is annotated with @Autowired, Spring will assume the responsibility for resolving all parameters in the constructor. Consequently, no other registered ParameterResolver will be able to resolve parameters.