public class SpringExtension extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.ParameterResolver
SpringExtension
integrates the Spring TestContext Framework
into JUnit 5's Jupiter programming model.
To use this class, simply annotate a JUnit Jupiter based test class with
@ExtendWith(SpringExtension.class)
.
DisabledIf
,
SpringJUnitConfig
,
SpringJUnitWebConfig
,
TestContextManager
Constructor and Description |
---|
SpringExtension() |
Modifier and Type | Method and Description |
---|---|
void |
afterAll(org.junit.jupiter.api.extension.ContainerExtensionContext context)
Delegates to
TestContextManager.afterTestClass() . |
void |
afterEach(org.junit.jupiter.api.extension.TestExtensionContext context)
|
void |
afterTestExecution(org.junit.jupiter.api.extension.TestExtensionContext context)
|
void |
beforeAll(org.junit.jupiter.api.extension.ContainerExtensionContext context)
Delegates to
TestContextManager.beforeTestClass() . |
void |
beforeEach(org.junit.jupiter.api.extension.TestExtensionContext context)
|
void |
beforeTestExecution(org.junit.jupiter.api.extension.TestExtensionContext context)
|
void |
postProcessTestInstance(Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context)
Delegates to
TestContextManager.prepareTestInstance(java.lang.Object) . |
Object |
resolve(org.junit.jupiter.api.extension.ParameterContext parameterContext,
org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Resolve a value for the
Parameter in the supplied
ParameterContext by retrieving the corresponding dependency
from the test's ApplicationContext . |
boolean |
supports(org.junit.jupiter.api.extension.ParameterContext parameterContext,
org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Determine if the value for the
Parameter in the supplied
ParameterContext should be autowired from the test's
ApplicationContext . |
public void beforeAll(org.junit.jupiter.api.extension.ContainerExtensionContext context) throws Exception
TestContextManager.beforeTestClass()
.beforeAll
in interface org.junit.jupiter.api.extension.BeforeAllCallback
Exception
public void afterAll(org.junit.jupiter.api.extension.ContainerExtensionContext context) throws Exception
TestContextManager.afterTestClass()
.afterAll
in interface org.junit.jupiter.api.extension.AfterAllCallback
Exception
public void postProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
TestContextManager.prepareTestInstance(java.lang.Object)
.postProcessTestInstance
in interface org.junit.jupiter.api.extension.TestInstancePostProcessor
Exception
public void beforeEach(org.junit.jupiter.api.extension.TestExtensionContext context) throws Exception
beforeEach
in interface org.junit.jupiter.api.extension.BeforeEachCallback
Exception
public void beforeTestExecution(org.junit.jupiter.api.extension.TestExtensionContext context) throws Exception
beforeTestExecution
in interface org.junit.jupiter.api.extension.BeforeTestExecutionCallback
Exception
public void afterTestExecution(org.junit.jupiter.api.extension.TestExtensionContext context) throws Exception
TestContextManager.afterTestExecution(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)
.afterTestExecution
in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback
Exception
public void afterEach(org.junit.jupiter.api.extension.TestExtensionContext context) throws Exception
TestContextManager.afterTestMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)
.afterEach
in interface org.junit.jupiter.api.extension.AfterEachCallback
Exception
public boolean supports(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
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(java.lang.reflect.Parameter)
.
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.
supports
in interface org.junit.jupiter.api.extension.ParameterResolver
resolve(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,
ParameterAutowireUtils.isAutowirable(java.lang.reflect.Parameter)
public Object resolve(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Parameter
in the supplied
ParameterContext
by retrieving the corresponding dependency
from the test's ApplicationContext
.
Delegates to ParameterAutowireUtils.resolveDependency(java.lang.reflect.Parameter, java.lang.Class<?>, org.springframework.context.ApplicationContext)
.
resolve
in interface org.junit.jupiter.api.extension.ParameterResolver
supports(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,
ParameterAutowireUtils.resolveDependency(java.lang.reflect.Parameter, java.lang.Class<?>, org.springframework.context.ApplicationContext)