public class EventPublishingTestExecutionListener extends AbstractTestExecutionListener
ApplicationContext
にテスト実行イベントを発行する TestExecutionListener
。イベントは、ApplicationContext
がすでにロードされている場合にのみ発行されます。BeforeTestClassEvent
PrepareTestInstanceEvent
BeforeTestMethodEvent
BeforeTestExecutionEvent
AfterTestExecutionEvent
AfterTestMethodEvent
AfterTestClassEvent
これらのイベントは、モック Bean のリセットやテスト実行のトレースなど、さまざまな理由で消費される可能性があります。カスタム TestExecutionListener
を実装するのではなく、テストイベントを使用する利点の 1 つは、テスト ApplicationContext
に登録されている Spring Bean によってテストイベントが消費される可能性があることです。そのような Bean は、依存関係の注入や ApplicationContext
の他の機能から直接恩恵を受けることができます。対照的に、TestExecutionListener
は ApplicationContext
の Bean ではありません。
デフォルトでは、テストイベントリスナーがテストイベントの使用中に例外をスローすると、その例外は使用中の基になるテストフレームワークに伝播します。例: BeforeTestMethodEvent
の使用により例外が発生した場合、対応するテストメソッドは例外の結果として失敗します。対照的に、非同期テストイベントリスナーが例外をスローした場合、その例外は基礎となるテストフレームワークに伝播しません。非同期例外処理の詳細については、@EventListener
のクラスレベルの Javadoc を参照してください。
特定のテストイベントリスナーでイベントを非同期に処理する場合は、Spring の @Async
サポートを使用できます。詳細については、@EventListener
のクラスレベルの Javadoc を参照してください。
@BeforeTestClass
, @PrepareTestInstance
, @BeforeTestMethod
, @BeforeTestExecution
, @AfterTestExecution
, @AfterTestMethod
, @AfterTestClass
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
コンストラクターと説明 |
---|
EventPublishingTestExecutionListener() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterTestClass(TestContext testContext) |
void | afterTestExecution(TestContext testContext) |
void | afterTestMethod(TestContext testContext) |
void | beforeTestClass(TestContext testContext) |
void | beforeTestExecution(TestContext testContext) |
void | beforeTestMethod(TestContext testContext) |
int | getOrder() 10000 を返します。 |
void | prepareTestInstance(TestContext testContext) |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public final int getOrder()
10000
を返します。Ordered
の getOrder
AbstractTestExecutionListener
の getOrder
Ordered.HIGHEST_PRECEDENCE
, Ordered.LOWEST_PRECEDENCE
public void beforeTestClass(TestContext testContext)
TestExecutionListener
の beforeTestClass
AbstractTestExecutionListener
の beforeTestClass
testContext
- テストのテストコンテキスト。null
public void prepareTestInstance(TestContext testContext)
TestExecutionListener
の prepareTestInstance
AbstractTestExecutionListener
の prepareTestInstance
testContext
- テストのテストコンテキスト。null
public void beforeTestMethod(TestContext testContext)
TestExecutionListener
の beforeTestMethod
AbstractTestExecutionListener
の beforeTestMethod
testContext
- テストメソッドが実行されるテストコンテキスト。非 null
TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
, TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
, TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
public void beforeTestExecution(TestContext testContext)
TestExecutionListener
の beforeTestExecution
AbstractTestExecutionListener
の beforeTestExecution
testContext
- テストメソッドが実行されるテストコンテキスト。非 null
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
, TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
, TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
public void afterTestExecution(TestContext testContext)
TestExecutionListener
の afterTestExecution
AbstractTestExecutionListener
の afterTestExecution
testContext
- テストメソッドが実行されるテストコンテキスト。非 null
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
, TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
, TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
public void afterTestMethod(TestContext testContext)
TestExecutionListener
の afterTestMethod
AbstractTestExecutionListener
の afterTestMethod
testContext
- テストメソッドが実行されたテストコンテキスト ; 決して null
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
, TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
, TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
public void afterTestClass(TestContext testContext)
TestExecutionListener
の afterTestClass
AbstractTestExecutionListener
の afterTestClass
testContext
- テストのテストコンテキスト。null