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, waitSEpublic void beforeAll(ExtensionContext context) throws ExceptionSE
TestContextManager.beforeTestClass() へのデリゲート。BeforeAllCallback の beforeAll ExceptionSEpublic void afterAll(ExtensionContext context) throws ExceptionSE
TestContextManager.afterTestClass() へのデリゲート。AfterAllCallback の afterAll ExceptionSEpublic void postProcessTestInstance(ObjectSE testInstance, ExtensionContext context) throws ExceptionSE
TestContextManager.prepareTestInstance(java.lang.Object) へのデリゲート。Spring Framework 5.3.2 の時点で、このメソッドは、テストメソッドとテストライフサイクルメソッドに @Autowired のアノテーションが付いていないことも検証します。
TestInstancePostProcessor の postProcessTestInstance ExceptionSEpublic void beforeEach(ExtensionContext context) throws ExceptionSE
BeforeEachCallback の beforeEach ExceptionSEpublic void beforeTestExecution(ExtensionContext context) throws ExceptionSE
BeforeTestExecutionCallback の beforeTestExecution ExceptionSEpublic void afterTestExecution(ExtensionContext context) throws ExceptionSE
AfterTestExecutionCallback の afterTestExecution ExceptionSEpublic void afterEach(ExtensionContext context) throws ExceptionSE
TestContextManager.afterTestMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable) へのデリゲート。AfterEachCallback の afterEach ExceptionSEpublic boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
ParameterContext の ParameterSE の値をテストの ApplicationContext からオートワイヤーする必要があるかどうかを決定します。 次のいずれかの条件が true の場合、パラメーターは自動書き込み可能と見なされます。
ConstructorSE であり、TestConstructorUtils.isAutowirableConstructor(Constructor, Class, PropertyProvider) は true を返します。isAutowirableConstructor() は、ルックアップを ExtensionContext.getConfigurationParameter(String) に委譲するフォールバック PropertyProvider で呼び出されることに注意してください。ApplicationContext またはそのサブ型です。ApplicationEvents またはそのサブ型です。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()