IntelliJ IDEA+TestNG:実行方法は各試験の前にグループ
-
25-09-2019 - |
質問
私は学習を利用TestNG for IntelliJ IDEAでは9.
調査を実施しているのは、同じ理解の一つの方法をテスト"と呼ばれるグループ name
では注釈がで @Test(group = "name")
.実行方法各試験の前に注釈を付けで @BeforeMethod
.
私の試験設定したいの方法を実行各試験の前にのみ、特定のグループに属するあなたの方法 beforeA
る各試験の前にグループ 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で浮き彫りにされたのは、全ての注釈のメッセージ"グループは定義されていません"または"グループBは未定義です。
なぜですか?
解決
- に上場さんはいつでも、intelliJす。テストを実行し、コマンドラインまたはmavenめの正しい。
@BeforeMethod
や@AfterMethod
そう壊れたとする。- IntelliJ覚えていく、使用前、ご利用の場合、グループは、できる限り少ない記憶なのに、メッセージ"群Xは定義されていません"と表示されます。だけでプレ alt + 入 は、未定義のグループを覚えています。
資源
他のヒント
私はそれを修正するためのIntelliJを尋ねました。問題を確認してください: http://youtrack.jetbrains.net/issue/IDEA-67653する JetBrainsのは、それを修正しますので、我々はそれに投票する必要があります。
@BeforeMethod(groups =...)
はAグループ内のすべてのメソッドの前に実行するように想定されていません。
これは、クラス内のすべてのメソッドの前に実行されます。違いはそれだけで何よりも、特定のグループに属しているだろう、です。 を参照してくださいDOCSする
としてはそれと同じグループに属しているのすべてのメソッドの前に実行するように想定されていないTEH EMPRAH @BeforeMethod挙げます。
あなたは正しくtestng.xml設定する必要があり、これを達成するために。あなたの予想出力のために、それはそう
のようになります。<suite....>
<test name="A">
<groups>
<run>
<include name="A"/>
</run>
</groups>
<classes>
<class name="...TestExample"/>
</classes>
</test>
<test name="B">
<groups>
<run>
<include name="B"/>
</run>
</groups>
<classes>
<class name="...TestExample"/>
</classes>
</test>
</suite>