public class SpringExtension
extends java.lang.Object
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
Modifier and Type | Field and Description |
---|---|
private static Namespace |
namespace
Namespace in which TestContextManagers are stored, keyed
by test class. |
Constructor and Description |
---|
SpringExtension() |
Modifier and Type | Method and Description |
---|---|
void |
afterAll(ContainerExtensionContext context)
Delegates to
TestContextManager.afterTestClass() . |
void |
afterEach(TestExtensionContext context)
|
void |
afterTestExecution(TestExtensionContext context)
|
void |
beforeAll(ContainerExtensionContext context)
Delegates to
TestContextManager.beforeTestClass() . |
void |
beforeEach(TestExtensionContext context)
|
void |
beforeTestExecution(TestExtensionContext context)
|
(package private) static ApplicationContext |
getApplicationContext(ExtensionContext context)
Get the
ApplicationContext associated with the supplied
ExtensionContext . |
private static TestContextManager |
getTestContextManager(ExtensionContext context)
Get the
TestContextManager associated with the supplied
ExtensionContext . |
void |
postProcessTestInstance(java.lang.Object testInstance,
ExtensionContext context)
Delegates to
TestContextManager.prepareTestInstance(java.lang.Object) . |
java.lang.Object |
resolve(ParameterContext parameterContext,
ExtensionContext extensionContext)
Resolve a value for the
Parameter in the supplied
ParameterContext by retrieving the corresponding dependency
from the test's ApplicationContext . |
boolean |
supports(ParameterContext parameterContext,
ExtensionContext extensionContext)
Determine if the value for the
Parameter in the supplied
ParameterContext should be autowired from the test's
ApplicationContext . |
private static final Namespace namespace
Namespace
in which TestContextManagers
are stored, keyed
by test class.public void beforeAll(ContainerExtensionContext context) throws java.lang.Exception
TestContextManager.beforeTestClass()
.java.lang.Exception
public void afterAll(ContainerExtensionContext context) throws java.lang.Exception
TestContextManager.afterTestClass()
.java.lang.Exception
public void postProcessTestInstance(java.lang.Object testInstance, ExtensionContext context) throws java.lang.Exception
TestContextManager.prepareTestInstance(java.lang.Object)
.java.lang.Exception
public void beforeEach(TestExtensionContext context) throws java.lang.Exception
java.lang.Exception
public void beforeTestExecution(TestExtensionContext context) throws java.lang.Exception
java.lang.Exception
public void afterTestExecution(TestExtensionContext context) throws java.lang.Exception
TestContextManager.afterTestExecution(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)
.java.lang.Exception
public void afterEach(TestExtensionContext context) throws java.lang.Exception
TestContextManager.afterTestMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)
.java.lang.Exception
public boolean supports(ParameterContext parameterContext, 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.
public java.lang.Object resolve(ParameterContext parameterContext, ExtensionContext extensionContext)
Parameter
in the supplied
ParameterContext
by retrieving the corresponding dependency
from the test's ApplicationContext
.
static ApplicationContext getApplicationContext(ExtensionContext context)
ApplicationContext
associated with the supplied
ExtensionContext
.context
- the current ExtensionContext
; never null
java.lang.IllegalStateException
- if an error occurs while retrieving the
application contextTestContext.getApplicationContext()
private static TestContextManager getTestContextManager(ExtensionContext context)
TestContextManager
associated with the supplied
ExtensionContext
.TestContextManager
; never null