クラス SpringJUnit4ClassRunner
- 実装されているすべてのインターフェース:
Describable、Filterable、Orderable、Sortable
- 既知の直属サブクラス
SpringRunner
SpringJUnit4ClassRunner は JUnit の BlockJUnit4ClassRunner のカスタム拡張であり、TestContextManager および関連するサポートクラスとアノテーションによって、Spring TestContext フレームワークの機能を標準の JUnit テストに提供します。 このクラスを使用するには、JUnit 4 ベースのテストクラスに @RunWith(SpringJUnit4ClassRunner.class) または @RunWith(SpringRunner.class) のアノテーションを付けます。
以下のリストは、現在 SpringJUnit4ClassRunner によって直接または間接的にサポートされているすべてのアノテーションを構成しています。(追加のアノテーションは、さまざまな TestExecutionListener または TestContextBootstrapper 実装によってサポートされる場合があることに注意してください)
@Test(expected=...)@Test(timeout=...)@Timed@Repeat@Ignore@ProfileValueSourceConfiguration@IfProfileValue
Spring TestContext フレームワークをこのランナー以外のランナーで使用する場合は、SpringClassRule および SpringMethodRule を使用します。
注意 : このクラスには、JUnit 4.12 以上が必要です。
- 導入:
- 2.5
- 作成者:
- Sam Brannen, Juergen Hoeller
- 関連事項:
コンストラクターの概要
コンストラクターメソッドのサマリー
修飾子と型メソッド説明protected ObjectSEテストインスタンスを作成するために親実装に委譲し、TestContextManagerがテストインスタンスを準備してから返すようにします。protected TestContextManagercreateTestContextManager(ClassSE<?> clazz) 提供されたテストクラスの新しいTestContextManagerを作成します。テストがクラスレベルで@IfProfileValueを介して無効になっている場合、無視されたテストクラスに適した説明を返します。それ以外の場合は、親実装に委譲します。protected ClassSE<? extends ThrowableSE>getExpectedException(FrameworkMethod frameworkMethod) 提供されたテストメソッドがスローすると予想されるexceptionを取得します。protected longgetJUnitTimeout(FrameworkMethod frameworkMethod) protected longgetSpringTimeout(FrameworkMethod frameworkMethod) protected final TestContextManagerこのランナーに関連付けられているTestContextManagerを取得します。protected booleanisTestMethodIgnored(FrameworkMethod frameworkMethod) protected StatementmethodBlock(FrameworkMethod frameworkMethod) 実行チェーン全体の潜在的な繰り返しで、デフォルトの JUnit 動作を強化します。protected StatementpossiblyExpectingExceptions(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement next) getExpectedException(FrameworkMethod)を使用して予期される例外が取得されることを除いて、BlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement)と同じロジックを実行します。voidrun(RunNotifier notifier) 現在の実行環境でテストが有効になっているかどうかを確認します。protected voidrunChild(FrameworkMethod frameworkMethod, RunNotifier notifier) テストがisTestMethodIgnored(FrameworkMethod)によって無視されると判断されることを除いて、BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier)と同じロジックを実行します。protected StatementwithAfterClasses(Statement statement) 親実装によって返されたStatementをRunAfterTestClassCallbacksステートメントでラップし、デフォルトの JUnit 機能を保持しながら、Spring TestContext フレームワークのサポートを追加します。protected StatementwithAfters(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 親実装によって返されたStatementをRunAfterTestMethodCallbacksステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。protected StatementwithAfterTestExecutionCallbacks(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 提供されたStatementをRunAfterTestExecutionCallbacksステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。protected StatementwithBeforeClasses(Statement statement) 親実装によって返されたStatementをRunBeforeTestClassCallbacksステートメントでラップし、デフォルトの JUnit 機能を保持しながら、Spring TestContext フレームワークのサポートを追加します。protected StatementwithBefores(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 親実装によって返されたStatementをRunBeforeTestMethodCallbacksステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。protected StatementwithBeforeTestExecutionCallbacks(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 提供されたStatementをRunBeforeTestExecutionCallbacksステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。protected StatementwithPotentialRepeat(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement next) 提供されたStatementをSpringRepeatステートメントでラップします。protected StatementwithPotentialTimeout(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement next) BlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement)と同じロジックを実行しますが、Spring の@Timedアノテーションを追加サポートします。クラス org.junit.runners.BlockJUnit4ClassRunner から継承されたメソッド
collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, getTestRules, isIgnored, methodInvoker, rules, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructorクラス org.junit.runners.ParentRunner から継承されたメソッド
childrenInvoker, classBlock, classRules, createTestClass, filter, getName, getRunnerAnnotations, getTestClass, order, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withInterruptIsolation
コンストラクターの詳細
SpringJUnit4ClassRunner
新しいSpringJUnit4ClassRunnerを作成し、TestContextManagerを初期化して、Spring Test 機能を標準の JUnit テストに提供します。- パラメーター:
clazz- 実行するテストクラス- 例外:
InitializationError- 関連事項:
メソッドの詳細
createTestContextManager
提供されたテストクラスの新しいTestContextManagerを作成します。サブクラスでオーバーライドできます。
- パラメーター:
clazz- 管理するテストクラス
getTestContextManager
このランナーに関連付けられているTestContextManagerを取得します。getDescription
テストがクラスレベルで@IfProfileValueを介して無効になっている場合、無視されたテストクラスに適した説明を返します。それ以外の場合は、親実装に委譲します。- 次で指定:
- インターフェース
DescribableのgetDescription - オーバーライド:
- クラス
ParentRunner<FrameworkMethod>のgetDescription - 関連事項:
run
現在の実行環境でテストが有効になっているかどうかを確認します。これにより、一致しない
@IfProfileValueアノテーションを持つクラスが完全に実行されなくなり、TestExecutionListenersのprepareTestInstance()メソッドの実行がスキップされます。withBeforeClasses
親実装によって返されたStatementをRunBeforeTestClassCallbacksステートメントでラップし、デフォルトの JUnit 機能を保持しながら、Spring TestContext フレームワークのサポートを追加します。- オーバーライド:
- クラス
ParentRunner<FrameworkMethod>のwithBeforeClasses - 関連事項:
withAfterClasses
親実装によって返されたStatementをRunAfterTestClassCallbacksステートメントでラップし、デフォルトの JUnit 機能を保持しながら、Spring TestContext フレームワークのサポートを追加します。- オーバーライド:
- クラス
ParentRunner<FrameworkMethod>のwithAfterClasses - 関連事項:
createTest
テストインスタンスを作成するために親実装に委譲し、TestContextManagerがテストインスタンスを準備してから返すようにします。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのcreateTest - 例外:
ExceptionSE- 関連事項:
runChild
テストがisTestMethodIgnored(FrameworkMethod)によって無視されると判断されることを除いて、BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier)と同じロジックを実行します。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのrunChild
methodBlock
実行チェーン全体の潜在的な繰り返しで、デフォルトの JUnit 動作を強化します。さらに、時間指定された実行内に
@Beforeおよび@Afterメソッドの実行を含めるために、タイムアウトのサポートが実行 チェーンに移動されました。これは、メインスレッドで@Beforeメソッドと@Afterメソッドを実行し、別のスレッドで実際のテストメソッドを実行するという JUnit のデフォルトの動作とは異なることに注意してください。正味の効果は、@Beforeおよび@Afterメソッドがテストメソッドと同じスレッドで実行されることです。結果として、JUnit で指定されたタイムアウトは、Spring トランザクションと組み合わせて正常に機能します。ただし、JUnit 固有のタイムアウトは、Spring 固有のタイムアウトとは異なります。前者は別のスレッドで実行され、後者はメインスレッドで実行されます (通常のテストのように)。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのmethodBlock - 関連事項:
BlockJUnit4ClassRunner.methodInvoker(FrameworkMethod, Object)withBeforeTestExecutionCallbacks(FrameworkMethod, Object, Statement)withAfterTestExecutionCallbacks(FrameworkMethod, Object, Statement)possiblyExpectingExceptions(FrameworkMethod, Object, Statement)withBefores(FrameworkMethod, Object, Statement)withAfters(FrameworkMethod, Object, Statement)withRulesReflectively(FrameworkMethod, Object, Statement)withPotentialRepeat(FrameworkMethod, Object, Statement)withPotentialTimeout(FrameworkMethod, Object, Statement)
isTestMethodIgnored
possiblyExpectingExceptions
protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement next) getExpectedException(FrameworkMethod)を使用して予期される例外が取得されることを除いて、BlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement)と同じロジックを実行します。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのpossiblyExpectingExceptions
getExpectedException
@Nullable protected ClassSE<? extends ThrowableSE> getExpectedException(FrameworkMethod frameworkMethod) 提供されたテストメソッドがスローすると予想されるexceptionを取得します。JUnit の
@Test(expected=...)アノテーションをサポートします。サブクラスでオーバーライドできます。
- 戻り値:
- 予期される例外、または何も指定されていない場合は
null
withPotentialTimeout
protected Statement withPotentialTimeout(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement next) BlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement)と同じロジックを実行しますが、Spring の@Timedアノテーションを追加サポートします。Spring の
@Timedアノテーションと JUnit の@Test(timeout=...)アノテーションの両方をサポートしますが、両方を同時にサポートすることはできません。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのwithPotentialTimeout - 戻り値:
- 必要に応じて、
SpringFailOnTimeout、FailOnTimeout、または提供されたStatementのいずれか - 関連事項:
getJUnitTimeout
- 戻り値:
- タイムアウト、または何も指定されなかった場合は
0
getSpringTimeout
- 戻り値:
- タイムアウト、または何も指定されなかった場合は
0 - 関連事項:
withBeforeTestExecutionCallbacks
protected Statement withBeforeTestExecutionCallbacks(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 提供されたStatementをRunBeforeTestExecutionCallbacksステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。withAfterTestExecutionCallbacks
protected Statement withAfterTestExecutionCallbacks(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 提供されたStatementをRunAfterTestExecutionCallbacksステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。withBefores
protected Statement withBefores(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 親実装によって返されたStatementをRunBeforeTestMethodCallbacksステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのwithBefores - 関連事項:
withAfters
protected Statement withAfters(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement statement) 親実装によって返されたStatementをRunAfterTestMethodCallbacksステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。- オーバーライド:
- クラス
BlockJUnit4ClassRunnerのwithAfters - 関連事項:
withPotentialRepeat
protected Statement withPotentialRepeat(FrameworkMethod frameworkMethod, ObjectSE testInstance, Statement next)