类 SpringExtension
- java.lang.Object
- org.springframework.test.context.junit.jupiter.SpringExtension
- 所有已实现的接口:
AfterAllCallback
,AfterEachCallback
,AfterTestExecutionCallback
,BeforeAllCallback
,BeforeEachCallback
,BeforeTestExecutionCallback
,Extension
,ParameterResolver
,TestInstancePostProcessor
public class SpringExtension extends Object implements 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
.- 从以下版本开始:
- 5.0
- 作者:
- Sam Brannen
- 另请参阅:
EnabledIf
,DisabledIf
,SpringJUnitConfig
,SpringJUnitWebConfig
,TestContextManager
构造器概要
构造器 构造器 说明 SpringExtension()
方法概要
构造器详细资料
SpringExtension
public SpringExtension()
方法详细资料
beforeAll
public void beforeAll(ExtensionContext context) throws Exception
Delegates toTestContextManager.beforeTestClass()
.- 指定者:
beforeAll
在接口中BeforeAllCallback
- 抛出:
Exception
afterAll
public void afterAll(ExtensionContext context) throws Exception
Delegates toTestContextManager.afterTestClass()
.- 指定者:
afterAll
在接口中AfterAllCallback
- 抛出:
Exception
postProcessTestInstance
public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception
Delegates toTestContextManager.prepareTestInstance(java.lang.Object)
.
beforeEach
public void beforeEach(ExtensionContext context) throws Exception
- 指定者:
beforeEach
在接口中BeforeEachCallback
- 抛出:
Exception
beforeTestExecution
public void beforeTestExecution(ExtensionContext context) throws Exception
afterTestExecution
public void afterTestExecution(ExtensionContext context) throws Exception
afterEach
public void afterEach(ExtensionContext context) throws Exception
Delegates toTestContextManager.afterTestMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)
.- 指定者:
afterEach
在接口中AfterEachCallback
- 抛出:
Exception
supportsParameter
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
Determine if the value for theParameter
in the suppliedParameterContext
should be autowired from the test'sApplicationContext
.A parameter is considered to be autowirable if one of the following conditions is
true
.- The declaring executable is a
Constructor
andTestConstructorUtils.isAutowirableConstructor(Constructor, Class)
returnstrue
. - The parameter is of type
ApplicationContext
or a sub-type thereof. ParameterResolutionDelegate.isAutowirable(java.lang.reflect.Parameter, int)
returnstrue
.
WARNING: If a test class
Constructor
is annotated with@Autowired
or automatically autowirable (seeTestConstructor
), Spring will assume the responsibility for resolving all parameters in the constructor. Consequently, no other registeredParameterResolver
will be able to resolve parameters.- 指定者:
supportsParameter
在接口中ParameterResolver
- 另请参阅:
resolveParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,TestConstructorUtils.isAutowirableConstructor(Constructor, Class)
,ParameterResolutionDelegate.isAutowirable(java.lang.reflect.Parameter, int)
- The declaring executable is a
resolveParameter
@Nullable public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
Resolve a value for theParameter
in the suppliedParameterContext
by retrieving the corresponding dependency from the test'sApplicationContext
.- 指定者:
resolveParameter
在接口中ParameterResolver
- 另请参阅:
supportsParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
,ParameterResolutionDelegate.resolveDependency(java.lang.reflect.Parameter, int, java.lang.Class<?>, org.springframework.beans.factory.config.AutowireCapableBeanFactory)
getApplicationContext
public static ApplicationContext getApplicationContext(ExtensionContext context)
Get theApplicationContext
associated with the suppliedExtensionContext
.- 参数:
context
- the currentExtensionContext
(nevernull
)- 返回:
- the application context
- 抛出:
IllegalStateException
- if an error occurs while retrieving the application context- 另请参阅:
TestContext.getApplicationContext()