IntelliJ IDEA 9 で TestNG を使用する方法を学んでいます。
私が理解している限り、というグループにテストを配置する1つの方法は、name
それに注釈を付けること@Test(group = "name")
です。各テストの前にメソッドを実行するには、 で注釈を付け@BeforeMethod
ます。
私のテスト設定では、特定のグループでのみ各テストの前にメソッドを実行したいと考えています。したがってbeforeA
、 group 内の各テストの前に実行されるA
メソッド、各テストのbeforeB
前に実行されるメソッドB
などがあります。
コード例:
public class TestExample
{
@BeforeMethod(groups = "A")
public void beforeA()
{
System.out.println("before A");
}
@BeforeMethod(groups = "B")
public void beforeB()
{
System.out.println("before B");
}
@Test(groups = "A")
public void A1()
{
System.out.println("test A1");
}
@Test(groups = "A")
public void A2()
{
System.out.println("test A2");
}
@Test(groups = "B")
public void B1()
{
System.out.println("test B1");
}
@Test(groups = "B")
public void B2()
{
System.out.println("test B2");
}
}
次のような出力が期待されます
before A
test A1
before A
test A2
before B
test B1
before B
test B2
しかし、私は次のようになります:
before A
before B
before A
before B
test A2
before A
before B
before A
before B
test B1
===============================================
test B2
===============================================
Custom suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
IntelliJ IDEA は、「グループ A は未定義です」または「グループ B は未定義です」というメッセージですべての注釈を強調表示しました。
私は何を間違っていますか?