文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 计算机软件及应用 > 如何解决TestNG Retry的问题
侵权投诉

如何解决TestNG Retry的问题

我们使用TestNG来作为自动化测试框架的基础。在运行一批test case之后呢,我们希望能够自动Retry failed的test case。TestNG提供了一个IRetryAnalyzer的接口,在@Test annotation里面可以指定使用Retry类来执行retry的功能。

@Test(retryAnalyzer = TestRetryAnalyzer.class)

TestRetryAnalyzer类实现了IRetryAnalyzer接口。

实现逻辑为:在retry方法里,判断Retry次数是否已经超过指定的最大retry次数。如果没有返回true,否则返回false。

_______________________________________________________________________________ importorg.testng.IRetryAnalyzer;

importorg.testng.ITestResult;

public class TestRetryAnalyzer implements IRetryAnalyzer {

private static final String TEST_RETRY_COUNT = "testRetryCount";

privateint count = 1;

privateintmaxCount = 1;

publicTestRetryAnalyzer() {

String retryMaxCount = System.getProperty(TEST_RETRY_COUNT);

if (retryMaxCount != null) {

maxCount = Integer.parseInt(retryMaxCount);

}

}

publicintgetCount() {

returnthis.count;

}

publicintgetMaxCount() {

returnthis.maxCount;

}

public synchronized boolean retry(ITestResult result) {

String testClassName = String.format("%s.%s", result.getMethod()

.getRealClass().toString(), result.getMethod().getMethodName());

if (count <= maxCount) {

result.setAttribute("RETRY", new Integer(count));

Logging.log("[RETRYING] " + testClassName + " FAILED, "

+ "Retrying " + count + " time", true);

count += 1;

return true;

第1页

你可能喜欢

热门文档

相关文档

  • 追求代码质量 JUnit4与TestNG的对比

    (Andrew Glover,testearly.com,2006 年 4 月):关亍如何在 TestNG 中重新运行...该公司通过有效的开发者测试策略和连续集成技术 帮劣企业解决软件质量问题,使开发...

  • 追求代码质量 JUnit4与TestNG的对比

    (Andrew Glover,testearly.com,2006 年 4 月):关亍如何在 TestNG 中重新运行...该公司通过有效的开发者测试策略和连续集成技术 帮劣企业解决软件质量问题,使开发...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email