public class SpringJUnit4ClassRunner
extends org.junit.runners.BlockJUnit4ClassRunnerSpringJUnit4ClassRunner は、JUnit の BlockJUnit4ClassRunner のカスタム拡張であり、TestContextManager および関連するサポートクラスとアノテーションを使用して、Spring TestContext フレームワークの機能を標準の JUnit テストに提供します。 このクラスを使用するには、@RunWith(SpringJUnit4ClassRunner.class) または @RunWith(SpringRunner.class) で JUnit 4 ベースのテストクラスにアノテーションを付けます。
以下のリストは、現在 SpringJUnit4ClassRunner によって直接または間接的にサポートされているすべてのアノテーションを構成しています。(追加のアノテーションは、さまざまな TestExecutionListener または TestContextBootstrapper 実装によってサポートされる場合があることに注意してください)
@Test(expected=...)@Test(timeout=...)@Timed@Repeat@Ignore@ProfileValueSourceConfiguration@IfProfileValueSpring TestContext フレームワークをこのランナー以外のランナーで使用する場合は、SpringClassRule および SpringMethodRule を使用します。
注意 : Spring Framework 4.3 以降、このクラスには JUnit 4.12 以上が必要です。
SpringRunner, TestContextManager, AbstractJUnit4SpringContextTests, AbstractTransactionalJUnit4SpringContextTests, SpringClassRule, SpringMethodRule| コンストラクターと説明 |
|---|
SpringJUnit4ClassRunner(java.lang.Class<?> clazz) |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected java.lang.Object | createTest() テストインスタンスを作成するために親実装に委譲し、 TestContextManager がテストインスタンスを準備してから返すようにします。 |
protected TestContextManager | createTestContextManager(java.lang.Class<?> clazz) 提供されたテストクラスの新しい TestContextManager を作成します。 |
org.junit.runner.Description | getDescription() テストがクラスレベルで @IfProfileValue を介して無効になっている場合、無視されたテストクラスに適した説明を返します。それ以外の場合は、親実装に委譲します。 |
protected java.lang.Class<? extends java.lang.Throwable> | getExpectedException(org.junit.runners.model.FrameworkMethod frameworkMethod) 提供されたテストメソッドがスローすると予想される exception を取得します。 |
protected long | getJUnitTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod) 提供されたテストメソッドの @Test アノテーションから構成済みの JUnit timeout を取得します。 |
protected long | getSpringTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod) 提供されたテストメソッドの @Timed アノテーションから、構成済みの Spring 固有の timeout を取得します。 |
protected TestContextManager | getTestContextManager() このランナーに関連付けられている TestContextManager を取得します。 |
protected boolean | isTestMethodIgnored(org.junit.runners.model.FrameworkMethod frameworkMethod) 提供されたテストメソッドに @Ignore が存在する場合、または @IfProfileValue を介してテストメソッドが無効になっている場合は、true を返します。 |
protected org.junit.runners.model.Statement | methodBlock(org.junit.runners.model.FrameworkMethod frameworkMethod) 実行チェーン全体の潜在的な繰り返しで、デフォルトの JUnit 動作を強化します。 |
protected org.junit.runners.model.Statement | possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement next) 予想される例外が getExpectedException(FrameworkMethod) を使用して取得されることを除いて、BlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement) と同じロジックを実行します。 |
void | run(org.junit.runner.notification.RunNotifier notifier) 現在の実行環境でテストが有効になっているかどうかを確認します。 |
protected void | runChild(org.junit.runners.model.FrameworkMethod frameworkMethod, org.junit.runner.notification.RunNotifier notifier) テストが isTestMethodIgnored(FrameworkMethod) によって無視されると決定されることを除いて、BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier) と同じロジックを実行します。 |
protected org.junit.runners.model.Statement | withAfterClasses(org.junit.runners.model.Statement statement) 親実装から返された Statement を RunAfterTestClassCallbacks ステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの JUnit 機能を保持します。 |
protected org.junit.runners.model.Statement | withAfters(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement statement) 親実装から返された Statement を RunAfterTestMethodCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。 |
protected org.junit.runners.model.Statement | withAfterTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement statement) 提供された Statement を RunAfterTestExecutionCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を維持します。 |
protected org.junit.runners.model.Statement | withBeforeClasses(org.junit.runners.model.Statement statement) 親実装から返された Statement を RunBeforeTestClassCallbacks ステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの JUnit 機能を保持します。 |
protected org.junit.runners.model.Statement | withBefores(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement statement) 親実装から返された Statement を RunBeforeTestMethodCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。 |
protected org.junit.runners.model.Statement | withBeforeTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement statement) 提供された Statement を RunBeforeTestExecutionCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を維持します。 |
protected org.junit.runners.model.Statement | withPotentialRepeat(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement next) 提供された Statement を SpringRepeat ステートメントでラップします。 |
protected org.junit.runners.model.Statement | withPotentialTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod, java.lang.Object testInstance, org.junit.runners.model.Statement next)BlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement) と同じロジックを実行しますが、Spring の @Timed アノテーションのサポートが追加されています。 |
collectInitializationErrors, computeTestMethods, describeChild, getChildren, getTestRules, isIgnored, methodInvoker, rules, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructorpublic SpringJUnit4ClassRunner(java.lang.Class<?> clazz)
throws org.junit.runners.model.InitializationErrorSpringJUnit4ClassRunner を作成し、TestContextManager を初期化して、Spring Test 機能を標準の JUnit テストに提供します。clazz - 実行するテストクラス org.junit.runners.model.InitializationErrorcreateTestContextManager(Class)protected TestContextManager createTestContextManager(java.lang.Class<?> clazz)
TestContextManager を作成します。サブクラスでオーバーライドできます。
clazz - 管理するテストクラス protected final TestContextManager getTestContextManager()
TestContextManager を取得します。public org.junit.runner.Description getDescription()
@IfProfileValue を介して無効になっている場合、無視されたテストクラスに適した説明を返します。それ以外の場合は、親実装に委譲します。org.junit.runner.Describable 内の getDescription org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod> の getDescription ProfileValueUtils.isTestEnabledInThisEnvironment(Class)public void run(org.junit.runner.notification.RunNotifier notifier)
これにより、一致しない @IfProfileValue アノテーションを持つクラスが完全に実行されなくなり、TestExecutionListeners の prepareTestInstance() メソッドの実行がスキップされます。
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod> の run ProfileValueUtils.isTestEnabledInThisEnvironment(Class), IfProfileValue, TestExecutionListenerprotected org.junit.runners.model.Statement withBeforeClasses(org.junit.runners.model.Statement statement)
Statement を RunBeforeTestClassCallbacks ステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの JUnit 機能を保持します。org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod> の withBeforeClasses RunBeforeTestClassCallbacksprotected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement)
Statement を RunAfterTestClassCallbacks ステートメントでラップし、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの JUnit 機能を保持します。org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod> の withAfterClasses RunAfterTestClassCallbacksprotected java.lang.Object createTest()
throws java.lang.ExceptionTestContextManager がテストインスタンスを準備してから返すようにします。org.junit.runners.BlockJUnit4ClassRunner の createTest java.lang.ExceptionTestContextManager.prepareTestInstance(java.lang.Object)protected void runChild(org.junit.runners.model.FrameworkMethod frameworkMethod,
org.junit.runner.notification.RunNotifier notifier)isTestMethodIgnored(FrameworkMethod) によって無視されると決定されることを除いて、BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier) と同じロジックを実行します。org.junit.runners.BlockJUnit4ClassRunner の runChild protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod frameworkMethod)
さらに、タイムアウトのサポートは、時間指定された実行内に @Before および @After メソッドの実行を含めるために、実行チェーンに移動されました。これは、メインスレッドで @Before メソッドと @After メソッドを実行し、別のスレッドで実際のテストメソッドを実行するデフォルトの JUnit の動作とは異なることに注意してください。最終的な効果は、@Before メソッドと @After メソッドがテストメソッドと同じスレッドで実行されることです。結果として、JUnit 指定のタイムアウトは Spring トランザクションと組み合わせて正常に機能します。ただし、JUnit 固有のタイムアウトは Spring 固有のタイムアウトとは異なり、前者は別のスレッドで実行され、後者は単純にメインスレッドで実行されます(通常のテストのように)。
org.junit.runners.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)protected boolean isTestMethodIgnored(org.junit.runners.model.FrameworkMethod frameworkMethod)
@Ignore が存在する場合、または @IfProfileValue を介してテストメソッドが無効になっている場合は、true を返します。protected org.junit.runners.model.Statement possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement next)getExpectedException(FrameworkMethod) を使用して取得されることを除いて、BlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement) と同じロジックを実行します。org.junit.runners.BlockJUnit4ClassRunner の possiblyExpectingExceptions @Nullable protected java.lang.Class<? extends java.lang.Throwable> getExpectedException(org.junit.runners.model.FrameworkMethod frameworkMethod)
exception を取得します。JUnit の @Test(expected=...) アノテーションをサポートします。
サブクラスでオーバーライドできます。
null protected org.junit.runners.model.Statement withPotentialTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement next)BlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement) と同じロジックを実行しますが、Spring の @Timed アノテーションのサポートが追加されています。Spring の @Timed アノテーションと JUnit の @Test(timeout=...) アノテーションの両方をサポートしますが、両方を同時にサポートすることはできません。
org.junit.runners.BlockJUnit4ClassRunner の withPotentialTimeout SpringFailOnTimeout、FailOnTimeout、付属の Statement のいずれか getSpringTimeout(FrameworkMethod), getJUnitTimeout(FrameworkMethod)protected long getJUnitTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod)
@Test アノテーションから構成済みの JUnit timeout を取得します。0 protected long getSpringTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod)
@Timed アノテーションから、構成済みの Spring 固有の timeout を取得します。0 TestAnnotationUtils.getTimeout(Method)protected org.junit.runners.model.Statement withBeforeTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement statement)Statement を RunBeforeTestExecutionCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を維持します。protected org.junit.runners.model.Statement withAfterTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement statement)Statement を RunAfterTestExecutionCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を維持します。protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement statement)Statement を RunBeforeTestMethodCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。org.junit.runners.BlockJUnit4ClassRunner の withBefores RunBeforeTestMethodCallbacksprotected org.junit.runners.model.Statement withAfters(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement statement)Statement を RunAfterTestMethodCallbacks ステートメントでラップします。これにより、Spring TestContext フレームワークのサポートを追加しながら、デフォルトの機能を保持します。org.junit.runners.BlockJUnit4ClassRunner の withAfters RunAfterTestMethodCallbacksprotected org.junit.runners.model.Statement withPotentialRepeat(org.junit.runners.model.FrameworkMethod frameworkMethod,
java.lang.Object testInstance,
org.junit.runners.model.Statement next)