我正在使用maven命令在TestNG框架中运行黄瓜测试。每天,我要从詹金斯执行测试用例,并在詹金斯生成黄瓜报告。 (使用黄瓜报告插件)
我正在寻找一种解决方案来重新运行Jenkins中失败的测试用例,它应该提供最终报告。
请向我提供实现此目标的方法。
最简单的方法是在TestNG中使用IRetryAnalyzer。它将重新运行失败的测试用例。
在最终报告中,如果重新运行通过,那么我将显示为通过(最初失败的一个显示为跳过)
如果重新运行也失败,则标记为失败。
示例:
public class Retry implements IRetryAnalyzer {
private int count = 0;
private static int maxTry = 3;
@Override
public boolean retry(ITestResult iTestResult) {
if (!iTestResult.isSuccess()) { //Check if test not succeed
if (count < maxTry) { //Check if maxtry count is reached
count++; //Increase the maxTry count by 1
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
return true; //Tells TestNG to re-run the test
} else {
iTestResult.setStatus(ITestResult.FAILURE); //If maxCount reached,test marked as failed
}
} else {
iTestResult.setStatus(ITestResult.SUCCESS); //If test passes, TestNG marks it as passed
}
return false;
}
}
在Testng.xml文件中添加
您也可以添加测试
@Test(retryAnalyzer = Retry.class)