29

最近、私は JUnit フレームワークを研究して実装しました。その結果、JUnit で使用されているいくつかの注釈を認識しています: - @Test@Before@After@Ignore@BeforeClass@AfterClass@Runwith(Suite.class)、および.@SuiteClasses({})@Parameters@RunWith(Parameterized.class)@Rule

JUnit で使用される注釈は他にもあると思います。使用できる注釈のリストと、それらがどのような状況で使用されるかを教えてもらえますか?

ありがとう。

4

1 に答える 1

56

この Github 検索 ( @interface) により、すべての注釈のリストが表示されます。

https://github.com/junit-team/junit/search?q=%22%40interface%22&type=コード

基本的な注釈

@Test @Before @After @AfterClass @BeforeClass @Ignore @Runwith

パラメータ化されたテスト

パラメーター化されたテストには、 https://github.com/junit-team/junit/wiki/Parameterized-tests を使用@Parameters@RunWith(Parameterized.class)
ます

カテゴリー

@Category
テストをカテゴリにグループ化します。例:速い、遅いなど

https://github.com/junit-team/junit/wiki/Categories

@IncludeCategory
注釈で指定されたカテゴリ、またはそのカテゴリのサブタイプで注釈が付けられたクラスとメソッドのみを実行@IncludeCategory します。

@ExcludeCategory
の逆@IncludeCategory

ルール

@Rule
ルールを使用すると、テスト クラス内の各テスト メソッドの動作を非常に柔軟に追加または再定義できます。たとえば、テストの実行中に一時フォルダーを作成するための一時フォルダー ルールを作成します。

https://github.com/junit-team/junit/wiki/Rules

理論と関連する注釈

@Theory
理論はより柔軟で表現力豊かな主張を与える

https://github.com/junit-team/junit/wiki/Theories

@DataPoint
フィールドまたはメソッドに注釈を付ける@DataPointと、フィールド値またはメソッドによって返される値が、そのクラスの理論の潜在的なパラメーターとして使用されます

@DataPoints

@Datapoint
配列または iterable 型のフィールドまたはメソッドにアノテーションを付ける拡張により、指定@DataPoints された配列または iterable の値が、そのクラスの理論の潜在的なパラメーターとして使用されるようになります

@FromDataPoints

@Theoryメソッドのパラメーターに注釈を付けると、@FromDataPointsそのパラメーターの潜在的な値と見なされるデータポイントが、指定された @DataPoints名前だけに制限されます

@ParametersSuppliedBy
@Theoryメソッド パラメーターに で 注釈を付けると、理論として実行されたとき@ParametersSuppliedByに名前付きから値が提供されます。ParameterSupplier

@TestedOn

@TestedOn注釈は、注釈付きパラメーターのデータ ポイントとして使用される値の配列を取ります。

例えば

@Theory
public void multiplyIsInverseOfDivideWithInlineDataPoints(
        @TestedOn(ints = {0, 5, 10}) int amount,
        @TestedOn(ints = {0, 1, 2}) int m
) {
    assumeThat(m, not(0));
    assertThat(new Dollar(amount).times(m).divideBy(m).getAmount(), is(amount));
}
于 2014-07-22T02:38:29.973 に答える