我正在为企业环境构建Selenium自动化套件的最后几个阶段。它配置了TestNG,运行在Jenkins上。该套件主要由UI测试组成。作为这种设置的典型,测试是片状的,在我们的时间表内,重新工作测试以减少对UI自动化的依赖是不可行的。
考虑到我已经在进行代码优化,我想设置一些自动重新运行失败测试的东西,以尽量减少手动检查故障的需要。我已经研究了几个选项,但是没有一个对我们的设置很有用:
rerunFailingTestsCount插件,但是这个特性只支持JUnit (我们使用TestNG)。建议的解决方案,将与我们的设置工作,将不胜感激。
发布于 2018-05-08 14:38:55
您可以添加重试侦听器:
重试班:
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class Retry implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 1;
public String getResultStatusName(int status) {
String resultName = null;
if (status == 1)
resultName = "SUCCESS";
if (status == 2)
resultName = "FAILURE";
if (status == 3)
resultName = "SKIP";
return resultName;
}
/*
* Below method returns 'true' if the test method has to be retried else
* 'false' and it takes the 'Result' as parameter of the test method that
* just ran
*
* @see org.testng.IRetryAnalyzer#retry(org.testng.ITestResult)
*/
@Override
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
System.out.println("Retrying test " + result.getName() + " with status " + getResultStatusName(result.getStatus()) + " for the " + (retryCount + 1) + " time(s).");
retryCount++;
return true;
}
return false;
}并添加以下侦听器:
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.IRetryAnalyzer;
import org.testng.annotations.ITestAnnotation;
public class RetryListener implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation testannotation, Class testClass, Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = testannotation.getRetryAnalyzer();
if (retry == null) {
testannotation.setRetryAnalyzer(Retry.class);
}
}
}您有两个选项可以调用上面的侦听器:
在您的xml测试运行器中,如下所示:
<listeners>
<listener class-name="package path....com.listeners.RetryListener" />
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>在考试课上:
@Listeners({ package path....com.listeners.RetryListener })您需要在类声明之前添加上述声明。
发布于 2018-05-08 02:37:04
对于失败的testNG测试,故障报告存储为testngfialed.xml。将它添加到XML套件中,这样的东西应该可以工作:
<suiteXmlFiles>
<suiteXmlFile>src/test/<your path>.../testng.xml</suiteXmlFile>
<suiteXmlFile>target/surefire-reports/testngfailed.xml</suiteXmlFile>
</suiteXmlFiles>发布于 2018-05-21 17:29:26
注意:此响应替换了先前被版主删除的响应。有关如何定义和连接TestNG重试分析器的详细信息,请参阅下一个响应。我更希望我的回应遵循这一观点,但它却出现在这里。
除了下面所示的TestNG套件文件方法之外,还可以通过服务加载器配置文件指定retry分析器。http://testng.org/doc/documentation-main.html#listeners-service-loader
这种ServiceLoader机制的优点是,无论项目是如何定义或如何运行,都可以按预期的方式工作。
https://stackoverflow.com/questions/50224928
复制相似问题