0
我有这样的例子代码:
与AfterMethod注解Run方法只有在规定的试验方法TestNG中
public class A {
@BeforeTest(groups = "group1")
public void beforeTest() {
System.out.println("Before test");
}
@BeforeMethod(groups = "group1")
public void beforeMethod() {
System.out.println("Before method");
}
@Test(groups = { "group1" })
public void test1() {
System.out.println("Test1");
}
@Test(groups = {"group2"})
public void test2() {
System.out.println("Test2");
}
@AfterMethod(groups = { "group2" }, alwaysRun = false)
public void afterMethod() {
System.out.println("After method");
}
@AfterTest(groups = "grupa1")
public void afterTest() {
System.out.println("AfterTest");
}
}
,输出是:
Before test
Before method
Test1
After method
Before method
Test2
After method
AfterTest
但我想收到像这样的东西:
Before test
Before method
Test1
Before method
Test2
After method
AfterTest
只有在第二种测试方法之后,有没有任何选项可以在Method方法后调用?我无法使用afterGroup注释。
你应该在这里定制你的解决方案。可能是共享变量/标志,表示是否运行测试,并将此标志作为“After Method”方法中的第一行。 –