自己的Report中把FailedCases显示出来。
在下面这个方法里面,我们在failedTests里面查找,如果failedCases里面没有该方法,就把该方法的结果删除掉。这样确保TestNG能够报告Suite的整体Pass/Fail状态。有些同学问,为什么要这么做?我们之前不是把testcase设置为skip了么?还记得我们前面提过的,TestNG可能会把result放在两个Map里面了,所以还是需要做这一步来确保正确。
privatevoidremoveFailedTestsInTestNG(ITestContext test)
…
} test.getFailedConfigurations().removeResult(result.getMethod()); } } } System.out.println("Passed:"+result.getMethod().getMethodName()); isFailed = true; break; } } if(!isFailed) { returnValue.removeResult(result.getMethod()); { IResultMapreturnValue = test.getFailedTests(); for(ITestResult result : returnValue.getAllResults()) { for(ITestResultresultToCheck : failedCases.getAllResults()) { if(result.getMethod().equals(resultToCheck.getMethod())) { booleanisFailed = false;
我们这么做了之后,基本能够保证报告的正确性。但是TestNG的Retry对DataProvider的支持不够好,详情参考
另外,此代码基于TestNG 6.7 之上。
CI 中也需要做修改,否则Retry成功了,CI仍然会报告失败。
(Andrew Glover,testearly.com,2006 年 4 月):关亍如何在 TestNG 中重新运行...该公司通过有效的开发者测试策略和连续集成技术 帮劣企业解决软件质量问题,使开发...
(Andrew Glover,testearly.com,2006 年 4 月):关亍如何在 TestNG 中重新运行...该公司通过有效的开发者测试策略和连续集成技术 帮劣企业解决软件质量问题,使开发...
热门文档