public class SpringExtension extends ObjectSE implements BeforeAllCallback, AfterAllCallback, TestInstancePostProcessor, BeforeEachCallback, AfterEachCallback, BeforeTestExecutionCallback, AfterTestExecutionCallback, ParameterResolver
SpringExtension
は、Spring TestContext フレームワークを JUnit 5 の Jupiter プログラミングモデルに統合します。 この拡張機能を使用するには、JUnit Jupiter ベースのテストクラスに @ExtendWith(SpringExtension.class)
、@SpringJUnitConfig
または @SpringJUnitWebConfig
アノテーションを付けるだけです。
EnabledIf
, DisabledIf
, SpringJUnitConfig
, SpringJUnitWebConfig
, TestContextManager
コンストラクターと説明 |
---|
SpringExtension() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterAll(ExtensionContext context) TestContextManager.afterTestClass() へのデリゲート。 |
void | afterEach(ExtensionContext context) |
void | afterTestExecution(ExtensionContext context) |
void | beforeAll(ExtensionContext context) TestContextManager.beforeTestClass() へのデリゲート。 |
void | beforeEach(ExtensionContext context) |
void | beforeTestExecution(ExtensionContext context) |
static ApplicationContext | getApplicationContext(ExtensionContext context) 提供された ExtensionContext に関連付けられた ApplicationContext を取得します。 |
void | postProcessTestInstance(ObjectSE testInstance, ExtensionContext context) |
ObjectSE | resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) |
boolean | supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public void beforeAll(ExtensionContext context) throws ExceptionSE
TestContextManager.beforeTestClass()
へのデリゲート。BeforeAllCallback
の beforeAll
ExceptionSE
public void afterAll(ExtensionContext context) throws ExceptionSE
TestContextManager.afterTestClass()
へのデリゲート。AfterAllCallback
の afterAll
ExceptionSE
public void postProcessTestInstance(ObjectSE testInstance, ExtensionContext context) throws ExceptionSE
TestInstancePostProcessor
の postProcessTestInstance
ExceptionSE
public void beforeEach(ExtensionContext context) throws ExceptionSE
BeforeEachCallback
の beforeEach
ExceptionSE
public void beforeTestExecution(ExtensionContext context) throws ExceptionSE
BeforeTestExecutionCallback
の beforeTestExecution
ExceptionSE
public void afterTestExecution(ExtensionContext context) throws ExceptionSE
AfterTestExecutionCallback
の afterTestExecution
ExceptionSE
public void afterEach(ExtensionContext context) throws ExceptionSE
TestContextManager.afterTestMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)
へのデリゲート。AfterEachCallback
の afterEach
ExceptionSE
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
ParameterContext
の Parameter
SE の値をテストの ApplicationContext
からオートワイヤーする必要があるかどうかを決定します。 次のいずれかの条件が true
の場合、パラメーターは自動書き込み可能と見なされます。
Constructor
SE であり、TestConstructorUtils.isAutowirableConstructor(Constructor, Class)
は true
を返します。ApplicationContext
またはそのサブタイプです。ParameterResolutionDelegate.isAutowirable(java.lang.reflect.Parameter, int)
は true
を返します。 警告 : テストクラス Constructor
に @Autowired
のアノテーションが付けられているか、自動的に自動書き込み可能(TestConstructor
を参照)の場合、Spring がコンストラクター内のすべてのパラメーターを解決する責任を負います。その結果、他の登録済み ParameterResolver
はパラメーターを解決できなくなります。
ParameterResolver
の supportsParameter
resolveParameter(org.junit.jupiter.api.extension.ParameterContext, org.junit.jupiter.api.extension.ExtensionContext)
, TestConstructorUtils.isAutowirableConstructor(Constructor, Class)
, ParameterResolutionDelegate.isAutowirable(java.lang.reflect.Parameter, int)
@Nullable public ObjectSE resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
ParameterResolver
の resolveParameter
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)
public static ApplicationContext getApplicationContext(ExtensionContext context)
ExtensionContext
に関連付けられた ApplicationContext
を取得します。context
- 現在の ExtensionContext
(非 null
)IllegalStateExceptionSE
- アプリケーションコンテキストの取得中にエラーが発生した場合 TestContext.getApplicationContext()