クラス SpringMethodRule

java.lang.ObjectSE
org.springframework.test.context.junit4.rules.SpringMethodRule
実装されているすべてのインターフェース:
MethodRule

@DeprecatedSE(since="7.0") public class SpringMethodRule extends ObjectSE implements MethodRule
使用すべきではありません。
Spring Framework 7.0 以降、SpringExtension と JUnit Jupiter が優先される
SpringMethodRule は、カスタム JUnit 4 MethodRule であり、TestContextManager および関連するサポートクラスとアノテーションを使用して、標準 JUnit テストで Spring TestContext フレームワークのインスタンスレベルおよびメソッドレベルの機能をサポートします。

SpringJUnit4ClassRunner とは対照的に、Spring のルールベースの JUnit サポートには、Runner から独立しているため、JUnit の Parameterized などの既存の代替ランナーや MockitoJUnitRunner などのサードパーティランナーと組み合わせることができるという利点があります。

ただし、SpringMethodRule は SpringJUnit4ClassRunner のインスタンスレベルおよびメソッドレベルの機能しかサポートしていないため、SpringJUnit4ClassRunner と同じ機能を実現するには、SpringMethodRule を SpringClassRule と組み合わせる必要があります。

使用例

 public class ExampleSpringIntegrationTest {

   @ClassRule
   public static final SpringClassRule springClassRule = new SpringClassRule();

   @Rule
   public final SpringMethodRule springMethodRule = new SpringMethodRule();

   // ...
}

以下のリストは、現在 SpringMethodRule によって直接または間接的にサポートされているすべてのアノテーションを構成しています。(追加のアノテーションは、さまざまな TestExecutionListener または TestContextBootstrapper 実装によってサポートされる場合があることに注意してください)

注意 : このクラスには、JUnit 4.12 以上が必要です。

警告 : JUnit ルールの欠点により、SpringMethodRule は、テストクラスのインスタンス化の直後ではなく、@Before ライフサイクルメソッドの前にテストインスタンスを準備します。さらに、SpringMethodRule は、TestExecutionListener API の beforeTestExecution() および afterTestExecution() コールバックをサポートしていません。

導入:
4.2
作成者:
Sam Brannen, Philippe Marschall
関連事項:
  • コンストラクターの概要

    コンストラクター
    コンストラクター
    説明
    使用すべきではありません。
  • メソッドのサマリー

    修飾子と型
    メソッド
    説明
    apply(Statement base, FrameworkMethod frameworkMethod, ObjectSE testInstance)
    使用すべきではありません。
    提供された base ステートメントに、Spring TestContext フレームワークの インスタンスレベルおよびメソッドレベルの機能を適用します

    クラス ObjectSE から継承されたメソッド

    clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSE
  • コンストラクターの詳細

    • SpringMethodRule

      public SpringMethodRule()
      使用すべきではありません。
  • メソッドの詳細

    • apply

      public Statement apply(Statement base, FrameworkMethod frameworkMethod, ObjectSE testInstance)
      使用すべきではありません。
      提供された base ステートメントに、Spring TestContext フレームワークの インスタンスレベルおよびメソッドレベルの機能を適用します

      具体的には、このメソッドは、TestContextManagerprepareTestInstance()beforeTestMethod()afterTestMethod() メソッドを呼び出します。Spring のタイムアウトと繰り返しが発生する可能性があります。

      さらに、このメソッドは、現在の実行環境でテストが有効になっているかどうかを確認します。これにより、一致しない @IfProfileValue アノテーションを持つメソッドが完全に実行されなくなり、TestExecutionListeners で prepareTestInstance() メソッドの実行がスキップされます。

      次で指定:
      インターフェース MethodRuleapply 
      パラメーター:
      base - このルールを適用する必要があるベース Statement 
      frameworkMethod - テストインスタンスで呼び出されようとしているメソッド
      testInstance - 現在のテストインスタンス
      戻り値:
      提供された base を、Spring TestContext フレームワークのインスタンスレベルおよびメソッドレベルの機能でラップするステートメント
      関連事項:
      • withBeforeTestMethodCallbacks(Statement, Method, Object, TestContextManager)
      • withAfterTestMethodCallbacks(Statement, Method, Object, TestContextManager)
      • withPotentialRepeat(Statement, Method, Object)
      • withPotentialTimeout(Statement, Method, Object)
      • withTestInstancePreparation(Statement, Object, TestContextManager)
      • withProfileValueCheck(Statement, Method, Object)