クラス EventPublishingTestExecutionListener
- 実装されているすべてのインターフェース:
Ordered, TestExecutionListener
ApplicationContext に公開する TestExecutionListener。サポートされるイベント
BeforeTestClassEventPrepareTestInstanceEventBeforeTestMethodEventBeforeTestExecutionEventAfterTestExecutionEventAfterTestMethodEventAfterTestClassEvent
これらのイベントは、モック Bean のリセットやテスト実行のトレースなど、さまざまな理由で発生する可能性があります。カスタム TestExecutionListener を実装するのではなくテストイベントを消費する利点の 1 つは、テスト ApplicationContext に登録されている任意の Spring Bean によってテストイベントが消費される可能性があることです。このような Bean は、依存性注入や ApplicationContext の他の機能から直接恩恵を受ける可能性があります。対照的に、TestExecutionListener は ApplicationContext の Bean ではありません。
EventPublishingTestExecutionListener はデフォルトで登録されていることに注意してください。ただし、ApplicationContext がすでにロードされている場合にのみイベントを公開します。これにより、ApplicationContext が不必要にロードされたり早すぎたりするのを防ぎます。ApplicationContext が別の TestExecutionListener によってロードされるまで、BeforeTestClassEvent は公開されません。例: TestExecutionListeners のデフォルトセットが登録されている場合、特定のテスト ApplicationContext を使用する最初のテストクラスに対して BeforeTestClassEvent は公開されませんが、同じテスト ApplicationContext を使用する同じテストスイート内の後続のテストクラスに対して BeforeTestClassEvent が公開されます。後続のテストクラスの実行時にコンテキストがすでにロードされているため(コンテキストが @DirtiesContext または最大サイズのエビクションポリシーを介して ContextCache から削除されていない場合)。BeforeTestClassEvent がすべてのテストクラスに対して公開されていることを確認する場合は、ApplicationContext を beforeTestClass コールバックにロードする TestExecutionListener を登録する必要があり、TestExecutionListener は EventPublishingTestExecutionListener の前に登録する必要があります。同様に、@DirtiesContext を使用して特定のテストクラスの最後のテストメソッドの後にコンテキストキャッシュから ApplicationContext を削除した場合、AfterTestClassEvent はそのテストクラスに対して公開されません。
例外処理
デフォルトでは、テストイベントリスナーがテストイベントの使用中に例外をスローすると、その例外は使用中の基になるテストフレームワークに伝播します。例: BeforeTestMethodEvent の使用により例外が発生した場合、対応するテストメソッドは例外の結果として失敗します。対照的に、非同期テストイベントリスナーが例外をスローした場合、その例外は基礎となるテストフレームワークに伝播しません。非同期例外処理の詳細については、@EventListener のクラスレベルの Javadoc を参照してください。
非同期リスナー
特定のテストイベントリスナーでイベントを非同期に処理する場合は、Spring の @Async サポートを使用できます。詳細については、@EventListener のクラスレベルの Javadoc を参照してください。
- 導入:
- 5.2
- 作成者:
- Sam Brannen, Frank Scheffler
- 関連事項:
フィールドのサマリー
フィールドインターフェース Ordered から継承されたフィールド
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEコンストラクターの概要
コンストラクター方法の概要
修飾子と型メソッド説明voidafterTestClass(TestContext testContext) voidafterTestExecution(TestContext testContext) voidafterTestMethod(TestContext testContext) voidbeforeTestClass(TestContext testContext) voidbeforeTestExecution(TestContext testContext) voidbeforeTestMethod(TestContext testContext) final intgetOrder()10000 を返します。これにより、EventPublishingTestExecutionListenerがSqlScriptsTestExecutionListenerの後、MockitoResetTestExecutionListenerの前に配置されることが保証されます。voidprepareTestInstance(TestContext testContext)
フィールドの詳細
ORDER
コンストラクターの詳細
EventPublishingTestExecutionListener
public EventPublishingTestExecutionListener()
メソッドの詳細
getOrder
public final int getOrder()10000 を返します。これにより、EventPublishingTestExecutionListenerがSqlScriptsTestExecutionListenerの後、MockitoResetTestExecutionListenerの前に配置されることが保証されます。- 次で指定:
- インターフェース
OrderedのgetOrder - オーバーライド:
- クラス
AbstractTestExecutionListenerのgetOrder - 戻り値:
- オーダー額
- 関連事項:
beforeTestClass
- 次で指定:
- インターフェース
TestExecutionListenerのbeforeTestClass - オーバーライド:
- クラス
AbstractTestExecutionListenerのbeforeTestClass - パラメーター:
testContext- テストのテストコンテキスト。null
prepareTestInstance
- 次で指定:
- インターフェース
TestExecutionListenerのprepareTestInstance - オーバーライド:
- クラス
AbstractTestExecutionListenerのprepareTestInstance - パラメーター:
testContext- テストのテストコンテキスト。null- 関連事項:
beforeTestMethod
- 次で指定:
- インターフェース
TestExecutionListenerのbeforeTestMethod - オーバーライド:
- クラス
AbstractTestExecutionListenerのbeforeTestMethod - パラメーター:
testContext- テストメソッドが実行されるテストコンテキスト。非null- 関連事項:
beforeTestExecution
- 次で指定:
- インターフェース
TestExecutionListenerのbeforeTestExecution - オーバーライド:
- クラス
AbstractTestExecutionListenerのbeforeTestExecution - パラメーター:
testContext- テストメソッドが実行されるテストコンテキスト。非null- 関連事項:
afterTestExecution
- 次で指定:
- インターフェース
TestExecutionListenerのafterTestExecution - オーバーライド:
- クラス
AbstractTestExecutionListenerのafterTestExecution - パラメーター:
testContext- テストメソッドが実行されるテストコンテキスト。非null- 関連事項:
afterTestMethod
- 次で指定:
- インターフェース
TestExecutionListenerのafterTestMethod - オーバーライド:
- クラス
AbstractTestExecutionListenerのafterTestMethod - パラメーター:
testContext- テストメソッドが実行されたテストコンテキスト ; 決してnull- 関連事項:
afterTestClass
- 次で指定:
- インターフェース
TestExecutionListenerのafterTestClass - オーバーライド:
- クラス
AbstractTestExecutionListenerのafterTestClass - パラメーター:
testContext- テストのテストコンテキスト。null