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