TestNG @BeforeGroups(inheritGroups = true)用法

时间:2016-02-19 01:51:26

标签: testng

我一直在玩TestNG并遇到一些我无法理解的行为,因为@BeforeGroups(inheritGroups = true)似乎没有用。 @BeforeSuite(inheritGroups = true)@BeforeTest(inheritGroups = true)@BeforeClass(inheritGroups = true)@BeforeMethod(inheritGroups = true)的位置确实如文档中所述。

在下面的代码段中,我明确地为各种(inheritGroups = true)执行@Before*注释参数。 @BeforeGroups是运行测试时未调用的唯一注释。此外,每个注释源代码都将inheritGroups = true作为默认值。即使没有在注释@BeforeGroups中明确设置它,也应该继承默认设置的类级别组。

代码

@Test(groups = "acceptance")
public class InheritTest {
    @BeforeSuite(inheritGroups = true)
    public void beforeSuite() {
        System.out.println("I am @BeforeSuite");
    }

    @BeforeTest(inheritGroups = true)
    public void beforeTest() {
        System.out.println("I am @BeforeTest");
    }

    @BeforeGroups
    public void beforeGroupsNoGroup() {
        System.out.println("I am @BeforeGroups");
    }

    @BeforeGroups(inheritGroups = true)
    public void beforeGroupsInherit() {
        System.out.println("I am @BeforeGroups(inheritGroups = true)");
    }

    @BeforeGroups(groups = { "acceptance" })
    public void beforeGroupsGroups() {
        System.out.println("I am @BeforeGroups(groups = {\"acceptance\"}");
    }

    @BeforeClass(inheritGroups = true)
    public void beforeClass() {
        System.out.println("I am @BeforeClass");
    }

    @BeforeMethod(inheritGroups = true)
    public void beforeMethod() {
        System.out.println("I am @BeforeMethod");
    }

    @Test
    public void test() {
        System.out.println("I am @Test");
    }
}

的testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite" verbose="1">
    <test name="Run Inherit Test">
        <groups>
            <run>
                <include name="acceptance" />
            </run>
        </groups>
        <classes>
            <class name="InheritTest" />
        </classes>
    </test>
</suite>

输出

I am @BeforeSuite
I am @BeforeTest
I am @BeforeClass
I am @BeforeGroups(groups = {"acceptance"}
I am @BeforeMethod
I am @Test

1 个答案:

答案 0 :(得分:2)

此问题以前报告为@BeforeGroups only called if group is specified explicitly · Issue #118 · cbeust/testng

您可以尝试在此处评论提及juherr (Julien Herr)cbeust (Cedric Beust)并在此处链接到您的Stack Overflow问题,看看您是否可以确认这是一个问题并将其修复。

相关问题