IntelliJ IDEA + TestNG:在组中的每个测试之前运行方法

Iai*_*der 2 testng intellij-idea

我正在学习使用TestNG进行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");
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望输出像

before A
test A1
before A
test A2
before B
test B1
before B
test B2
Run Code Online (Sandbox Code Playgroud)

但我得到以下内容:

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
===============================================
Run Code Online (Sandbox Code Playgroud)

并且IntelliJ IDEA突出显示了我的所有注释,其中包含"组A未定义"或"组B未定义"的消息.

我究竟做错了什么?

Col*_*ert 16

  1. 列表不是很好,这是intelliJ的错.在命令行或maven中运行测试,订单将是正确的.
  2. @BeforeMethod并且@AfterMethod似乎被团体打破了.
  3. IntelliJ记住您之前使用过的组,如果您使用的组尚未记住,则会显示消息"组X未定义".只需在未定义的组上按alt+ Enter即可记住它.

资源: