インターフェースの使用
org.springframework.test.context.TestContext
TestContext を使用するパッケージ
パッケージ
説明
このパッケージには Spring TestContext フレームワークが含まれており、使用中の実際のテストフレームワークにとらわれないアノテーション駆動型ユニットおよび統合テストのサポートを提供します。
Spring Test でケースバイケースの Bean オーバーライドをサポートします。
Mockito のモックとスパイに基づく Bean オーバーライドメカニズム。
Spring TestContext フレームワークのテストイベントサポートクラス。
JDBC は、
@Sql を介した宣言的な SQL スクリプト実行のサポートを含む、Spring TestContext フレームワークのクラスをサポートします。Spring TestContext フレームワークのサポートクラス。
Spring TestContext フレームワークのトランザクションサポートクラス。
Web は、Spring TestContext フレームワークのクラスをサポートします。
org.springframework.test.context 内の TestContext 使用
TestContext を返す org.springframework.test.context のメソッド修飾子と型メソッド説明TestContextBootstrapper.buildTestContext()このブートストラップに関連付けられているBootstrapContextのTestContextをビルドします。final TestContextTestContextManager.getTestContext()このTestContextManagerによって管理されるTestContextを取得します。型 TestContext のパラメーターを持つ org.springframework.test.context のメソッド修飾子と型メソッド説明default voidTestExecutionListener.afterTestClass(TestContext testContext) クラス内のすべてのテストを実行した後、テストクラスを後処理します。default voidTestExecutionListener.afterTestExecution(TestContext testContext) 提供されたテストコンテキスト でテストメソッドSEを実行した直後に、タイミングやログ記録などの目的でテストを後処理します。default voidTestExecutionListener.afterTestMethod(TestContext testContext) たとえば、テストフィクスチャを切断することによって - 基本的なテストフレームワークのライフサイクルコールバック後の実行後にテストをポスト処理します。default voidTestExecutionListener.beforeTestClass(TestContext testContext) クラス内のすべてのテストを実行する前に、テストクラスを前処理します。default voidTestExecutionListener.beforeTestExecution(TestContext testContext) 提供されたテストコンテキスト でテストメソッドSEを実行する直前に、タイミングやログ記録などの目的でテストを前処理します。default voidTestExecutionListener.beforeTestMethod(TestContext testContext) 基礎となるテストフレームワークのライフサイクル前コールバックの実行前にテストを前処理します。たとえば、テストフィクスチャをセットアップします。default voidTestExecutionListener.prepareTestInstance(TestContext testContext) 提供されたテストコンテキスト のテストインスタンスSEを準備します。たとえば、依存関係を注入します。型 TestContext の型引数を持つ org.springframework.test.context のメソッドパラメーター修飾子と型メソッド説明default voidTestContext.publishEvent(FunctionSE<TestContext, ? extends ApplicationEvent> eventFactory) org.springframework.test.context.bean.override 内の TestContext 使用
型 TestContext のパラメーターを持つ org.springframework.test.context.bean.override のメソッド修飾子と型メソッド説明voidBeanOverrideTestExecutionListener.beforeTestMethod(TestContext testContext) voidBeanOverrideTestExecutionListener.prepareTestInstance(TestContext testContext) org.springframework.test.context.bean.override.mockito 内の TestContext 使用
型 TestContext のパラメーターを持つ org.springframework.test.context.bean.override.mockito のメソッド修飾子と型メソッド説明voidMockitoResetTestExecutionListener.afterTestMethod(TestContext testContext) voidMockitoResetTestExecutionListener.beforeTestMethod(TestContext testContext) org.springframework.test.context.event 内の TestContext 使用
修飾子と型メソッド説明final TestContextTestContextEvent.getSource()このイベントに関連付けられているTestContextを取得します。final TestContextTestContextEvent.getTestContext()TestContextEvent.getSource()のエイリアス。型 TestContext のパラメーターを持つ org.springframework.test.context.event のメソッド修飾子と型メソッド説明voidEventPublishingTestExecutionListener.afterTestClass(TestContext testContext) voidEventPublishingTestExecutionListener.afterTestExecution(TestContext testContext) voidApplicationEventsTestExecutionListener.afterTestMethod(TestContext testContext) voidEventPublishingTestExecutionListener.afterTestMethod(TestContext testContext) voidEventPublishingTestExecutionListener.beforeTestClass(TestContext testContext) voidEventPublishingTestExecutionListener.beforeTestExecution(TestContext testContext) voidApplicationEventsTestExecutionListener.beforeTestMethod(TestContext testContext) voidEventPublishingTestExecutionListener.beforeTestMethod(TestContext testContext) voidApplicationEventsTestExecutionListener.prepareTestInstance(TestContext testContext) voidEventPublishingTestExecutionListener.prepareTestInstance(TestContext testContext) 型 TestContext のパラメーターを持つ org.springframework.test.context.event のコンストラクター修飾子コンストラクター説明AfterTestClassEvent(TestContext source) AfterTestExecutionEvent(TestContext source) AfterTestMethodEvent(TestContext source) BeforeTestClassEvent(TestContext source) BeforeTestExecutionEvent(TestContext source) BeforeTestMethodEvent(TestContext source) PrepareTestInstanceEvent(TestContext source) TestContextEvent(TestContext source) 新しいTestContextEventを作成します。org.springframework.test.context.jdbc 内の TestContext 使用
型 TestContext のパラメーターを持つ org.springframework.test.context.jdbc のメソッド修飾子と型メソッド説明voidSqlScriptsTestExecutionListener.afterTestClass(TestContext testContext) すべてのテストメソッドが実行された後、指定されたTestContextに対して@Sql経由で構成された SQL スクリプトをテストクラスごとに 1 回実行します。voidSqlScriptsTestExecutionListener.afterTestMethod(TestContext testContext) 現在のテストメソッドの後に、指定されたTestContextに対して@Sqlを介して構成された SQL スクリプトを実行します。voidSqlScriptsTestExecutionListener.beforeTestClass(TestContext testContext) テストメソッドを実行する前に、指定されたTestContextに対して@Sql経由で構成された SQL スクリプトをテストクラスごとに 1 回実行します。voidSqlScriptsTestExecutionListener.beforeTestMethod(TestContext testContext) 現在のテストメソッドの前に、提供されたTestContextに対して@Sqlを介して構成された SQL スクリプトを実行します。org.springframework.test.context.support 内の TestContext 使用
TestContext を実装している org.springframework.test.context.support のクラス修飾子と型メソッド説明AbstractTestContextBootstrapper.buildTestContext()このブートストラッパーに関連付けられたBootstrapContextのテストクラスSEを使用し、AbstractTestContextBootstrapper.buildMergedContextConfiguration()およびAbstractTestContextBootstrapper.getCacheAwareContextLoaderDelegate()に委譲することにより、新しいDefaultTestContextをビルドします。型 TestContext のパラメーターを持つ org.springframework.test.context.support のメソッド修飾子と型メソッド説明voidAbstractTestExecutionListener.afterTestClass(TestContext testContext) デフォルトの実装は空です。voidCommonCachesTestExecutionListener.afterTestClass(TestContext testContext) voidDirtiesContextTestExecutionListener.afterTestClass(TestContext testContext) 指定されたテストコンテキストのテストクラスに@DirtiesContextアノテーションが付けられ、クラスモードがAFTER_CLASSに設定されている場合、テストコンテキストのアプリケーションコンテキストは ダーティとしてマークされ、テストコンテキストのREINJECT_DEPENDENCIES_ATTRIBUTEはtrueに設定されます。voidAbstractTestExecutionListener.afterTestExecution(TestContext testContext) デフォルトの実装は空です。voidAbstractTestExecutionListener.afterTestMethod(TestContext testContext) デフォルトの実装は空です。voidDirtiesContextTestExecutionListener.afterTestMethod(TestContext testContext) 指定されたテストコンテキストの現在のテストメソッドに@DirtiesContextのアノテーションが付けられ、メソッドモードがAFTER_METHODに設定されている場合、またはテストクラスに@DirtiesContextのアノテーションが付けられ、クラスモードがAFTER_EACH_TEST_METHODに設定されている場合、テストコンテキストのアプリケーションコンテキストは次のようになります。ダーティとしてマークされ、テストコンテキストのREINJECT_DEPENDENCIES_ATTRIBUTEはtrueに設定されます。protected voidAbstractDirtiesContextTestExecutionListener.beforeOrAfterTestClass(TestContext testContext, DirtiesContext.ClassMode requiredClassMode) 必要に応じて(つまり、必要なモードに従って)コンテキストをダーティ化することにより、AbstractTestExecutionListener.beforeTestClass(TestContext)およびAbstractTestExecutionListener.afterTestClass(TestContext)の実際の作業を実行します。protected voidAbstractDirtiesContextTestExecutionListener.beforeOrAfterTestMethod(TestContext testContext, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) 必要に応じて(つまり、必要なモードに従って)コンテキストをダーティ化することにより、AbstractTestExecutionListener.beforeTestMethod(TestContext)およびAbstractTestExecutionListener.afterTestMethod(TestContext)の実際の作業を実行します。voidAbstractTestExecutionListener.beforeTestClass(TestContext testContext) デフォルトの実装は空です。voidDirtiesContextBeforeModesTestExecutionListener.beforeTestClass(TestContext testContext) 指定されたテストコンテキストのテストクラスに@DirtiesContextアノテーションが付けられ、クラスモードがBEFORE_CLASSに設定されている場合、テストコンテキストのアプリケーションコンテキストは ダーティとしてマークされ、テストコンテキストのREINJECT_DEPENDENCIES_ATTRIBUTEはtrueに設定されます。voidAbstractTestExecutionListener.beforeTestExecution(TestContext testContext) デフォルトの実装は空です。voidAbstractTestExecutionListener.beforeTestMethod(TestContext testContext) デフォルトの実装は空です。voidDependencyInjectionTestExecutionListener.beforeTestMethod(TestContext testContext) 提供されたtest contextのDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTEの値がBoolean.TRUESE である場合、このメソッドはprepareTestInstance()と同じ効果があります。それ以外の場合、このメソッドは効果がありません。voidDirtiesContextBeforeModesTestExecutionListener.beforeTestMethod(TestContext testContext) 指定されたテストコンテキストの現在のテストメソッドに@DirtiesContextのアノテーションが付けられ、メソッドモードがBEFORE_METHODに設定されている場合、またはテストクラスに@DirtiesContextのアノテーションが付けられ、クラスモードがBEFORE_EACH_TEST_METHODに設定されている場合、テストコンテキストのアプリケーションコンテキストは次のようになります。ダーティとしてマークされ、テストコンテキストのREINJECT_DEPENDENCIES_ATTRIBUTEはtrueに設定されます。protected voidAbstractDirtiesContextTestExecutionListener.dirtyContext(TestContext testContext, @Nullable DirtiesContext.HierarchyMode hierarchyMode) 指定されたテストコンテキストのアプリケーションコンテキストを ダーティとしてマークし、テストコンテキストのREINJECT_DEPENDENCIES_ATTRIBUTEをtrueに設定します。protected voidDependencyInjectionTestExecutionListener.injectDependencies(TestContext testContext) prepareTestInstance()に従って、提供されたTestContextの依存性注入と Bean 初期化を実行します。voidAbstractTestExecutionListener.prepareTestInstance(TestContext testContext) デフォルトの実装は空です。voidDependencyInjectionTestExecutionListener.prepareTestInstance(TestContext testContext) 独自のapplication contextを介して、autowiringおよびinitializingによって提供されたtest contextのtest instanceに依存関係の注入を実行します(依存関係をチェックしません)。org.springframework.test.context.transaction 内の TestContext 使用
型 TestContext のパラメーターを持つ org.springframework.test.context.transaction のメソッド修飾子と型メソッド説明voidTransactionalTestExecutionListener.afterTestMethod(TestContext testContext) 指定されたテストコンテキストに対してトランザクションが現在アクティブである場合、このメソッドはトランザクションを終了し、@AfterTransactionメソッドを実行します。voidTransactionalTestExecutionListener.beforeTestMethod(TestContext testContext) 指定されたテストコンテキストのテストメソッドがトランザクション内で実行されるように構成されている場合、このメソッドは@BeforeTransactionメソッドを実行し、新しいトランザクションを開始します。static TransactionAttributeTestContextTransactionUtils.createDelegatingTransactionAttribute(TestContext testContext, TransactionAttribute targetAttribute) テストクラスの名前とテストメソッドを使用してトランザクションの名前を作成し、提供されたターゲットTransactionAttributeおよびTestContextの委譲TransactionAttributeを作成します。static TransactionAttributeTestContextTransactionUtils.createDelegatingTransactionAttribute(TestContext testContext, TransactionAttribute targetAttribute, boolean includeMethodName) テストクラスの名前とテストメソッド (リクエストされた場合) を使用してトランザクションの名前を構築し、指定されたターゲットTransactionAttributeおよびTestContextの委譲TransactionAttributeを作成します。protected @Nullable PlatformTransactionManagerTransactionalTestExecutionListener.getTransactionManager(TestContext testContext) 指定されたテストコンテキストに使用するトランザクションマネージャーを取得します。protected @Nullable PlatformTransactionManagerTransactionalTestExecutionListener.getTransactionManager(TestContext testContext, @Nullable StringSE qualifier) protected final booleanTransactionalTestExecutionListener.isDefaultRollback(TestContext testContext) 提供されたテストコンテキストに対して、デフォルトでトランザクションをロールバックするかどうかを決定します。protected final booleanTransactionalTestExecutionListener.isRollback(TestContext testContext) デフォルトのロールバックフラグと、@Rollbackアノテーションを介したメソッドレベルのオーバーライドの可能性を考慮して、提供されたテストコンテキストのトランザクションをロールバックするかどうかを決定します。static @Nullable DataSourceSETestContextTransactionUtils.retrieveDataSource(TestContext testContext, @Nullable StringSE name) 指定されたテストコンテキストに使用するDataSourceSE を取得します。TestContextTransactionUtils.retrieveTransactionManager(TestContext testContext, @Nullable StringSE name) 指定されたテストコンテキストに使用するトランザクションマネージャーを取得します。protected voidTransactionalTestExecutionListener.runAfterTransactionMethods(TestContext testContext) 指定されたテストコンテキストに対してすべての@AfterTransactionメソッドを実行します。protected voidTransactionalTestExecutionListener.runBeforeTransactionMethods(TestContext testContext) 指定されたテストコンテキストに対してすべての@BeforeTransactionメソッドを実行します。org.springframework.test.context.web 内の TestContext 使用
型 TestContext のパラメーターを持つ org.springframework.test.context.web のメソッド修飾子と型メソッド説明voidServletTestExecutionListener.afterTestMethod(TestContext testContext) 提供されたTestContextのServletTestExecutionListener.RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTEの値がBoolean.TRUESE である場合、このメソッドは、(1)Spring Web のRequestContextHolderをリセットして各テストメソッドの後にスレッドローカル状態をクリーンアップし、(2) 新しいモックが後続のテストインスタンスに確実に挿入されるようにします。テストコンテキストのDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTEをtrueに設定してテストします。voidServletTestExecutionListener.beforeTestMethod(TestContext testContext) Spring Web のRequestContextHolderを介して各テストメソッドの前にスレッドローカル状態を設定します。ただし、テストクラスに@WebAppConfigurationアノテーションが付けられている場合のみです。voidServletTestExecutionListener.prepareTestInstance(TestContext testContext) Spring Web のRequestContextHolderを介したテストインスタンス準備コールバックフェーズ中にスレッドローカル状態をセットアップしますが、テストクラスに@WebAppConfigurationアノテーションが付けられている場合のみです。