我有一个监听器类,它实现了 IResultListener。在该类中,我实现了 onConfigurationSuccess 方法,在测试方法之后执行一些操作。但是@AfterMethod注解的方法在同一个测试方法之后会被调用两次。我用控制台输出检查这一点:
public void onConfigurationSuccess(ITestResult itr) {
if (itr.getMethod().isAfterMethodConfiguration()) {
System.out.println("Aftermethod: " + itr.getMethod().getMethodName());
Object[] parameters = itr.getParameters();
ITestResult originalResult = (ITestResult) parameters[0];
System.out.println("Testmethod: " + originalResult.getMethod().getMethodName());
}
}
有人有同样的问题吗?我只有一个 @AfterMethod 方法,并且 testmethod 运行一次。这是 testng 中的错误吗?
最佳答案
我使用的是testng版本6.3.1,问题只出现在这里。在实际版本 6.5.2 中它工作正常。
关于java - @AfterMethod 在 onConfigurationSuccess 方法中被调用两次。 TestNG 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10898893/