我正在学习将 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");
}
}
我希望输出像
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 组未定义”突出显示了我的所有注释。
我究竟做错了什么?
最佳答案
@BeforeMethod
和 @AfterMethod
似乎与团体破裂。 资源:
关于intellij-idea - IntelliJ IDEA + TestNG : Run a method before each test in a group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3602404/