java TestNG:@BeforeGroups为每个组条目调用,即使我正在运行一组测试
我在testNG测试中发现了一个问题,测试如下
public class testNG {
@BeforeGroups(groups = {"smoketests", "functionaltests"})
public void before() {
System.out.println("Before Groups");
}
@Test(groups = {"smoketests", "functionaltests"})
public void test() {
System.out.println("Test");
}
@AfterGroups(groups = {"smoketests", "functionaltests"})
public void after() {
System.out.println("After Groups");
}
}
当我从testNG命令行运行测试时
java-cp:libs/*org。testng。testNGLib-testngs。jar测试
(假设测试jar位于某个libs文件夹中)
我得到的结果如下
Before Groups
Before Groups
Test
After Groups
我不知道为什么BeforeGroups会被调用两次,尽管我只对运行作为smoketests组一部分的测试感兴趣
如果@Test指令中只有smoketests组,则不会出现问题,但我仍然不理解@BeforeGroups中存在多个组的问题
# 1 楼答案
运行测试套件时遇到相同问题
以下是测试等级:
所以当我运行testng时。xml,获得以下结果:
以下是将组名更改为“回归”后的结果
对这两个组条目执行@BefroreGroups和@Aftergroups。使用TestNG 6.11版本
# 2 楼答案
试用
@BeforeSuite(alwaysRun = true)
而不是@BeforeGroups(groups = {"smoketests", "functionaltests"})
@AfterSuite(alwaysRun = true)
而不是@AfterGroups(groups = {"smoketests", "functionaltests"})