TestNG @BeforeGroups(inheritGroups = true) 用法
TestNG @BeforeGroups(inheritGroups = true) usage
我一直在玩 TestNG,运行 出现了一些我无法理解的行为,因为 @BeforeGroups(inheritGroups = true)
似乎不起作用。其中 @BeforeSuite(inheritGroups = true)
、@BeforeTest(inheritGroups = true)
、@BeforeClass(inheritGroups = true)
和 @BeforeMethod(inheritGroups = true)
确实按照文档中的描述工作。
在下面的代码片段中,我明确地为各种 @Before*
使用了 (inheritGroups = true)
注释参数。 @BeforeGroups
是测试为 运行 时唯一未被调用的注释。此外,每个注释源代码都有 inheritGroups = true 作为默认值。即使没有在注释中明确设置它 @BeforeGroups
也应该继承默认设置的 class 级别组。
代码
@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
此问题之前已被报告为 @BeforeGroups only called if group is specified explicitly · Issue #118 · cbeust/testng。
您可以尝试在此处评论提及 juherr (Julien Herr) or cbeust (Cedric Beust) 并在此处链接到您的 Stack Overflow 问题,以查看您是否可以在确认这是一个问题并解决问题时获得一些支持。
我一直在玩 TestNG,运行 出现了一些我无法理解的行为,因为 @BeforeGroups(inheritGroups = true)
似乎不起作用。其中 @BeforeSuite(inheritGroups = true)
、@BeforeTest(inheritGroups = true)
、@BeforeClass(inheritGroups = true)
和 @BeforeMethod(inheritGroups = true)
确实按照文档中的描述工作。
在下面的代码片段中,我明确地为各种 @Before*
使用了 (inheritGroups = true)
注释参数。 @BeforeGroups
是测试为 运行 时唯一未被调用的注释。此外,每个注释源代码都有 inheritGroups = true 作为默认值。即使没有在注释中明确设置它 @BeforeGroups
也应该继承默认设置的 class 级别组。
代码
@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
此问题之前已被报告为 @BeforeGroups only called if group is specified explicitly · Issue #118 · cbeust/testng。
您可以尝试在此处评论提及 juherr (Julien Herr) or cbeust (Cedric Beust) 并在此处链接到您的 Stack Overflow 问题,以查看您是否可以在确认这是一个问题并解决问题时获得一些支持。