如何使用Gradle重新运行失败的TestNG测试 [英] How to re-run failed TestNG tests using Gradle

查看:156
本文介绍了如何使用Gradle重新运行失败的TestNG测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道什么TestNG生成带有有关失败测试信息的testng-failed.xml. 我想在Gradle中使用它来创建新任务以运行失败的测试:

I know what TestNG generates testng-failed.xml with information about failed test. I'd like to use it in Gradle to created new task for running failed tests:

task secondTry(type: Test) {
onlyIf {
    file("build/reports/tests/test/testng-failed.xml").exists()
}
println file("build/reports/tests/test/testng-failed.xml").exists()

testClassesDir = sourceSets.test.output.classesDir
classpath = sourceSets.test.runtimeClasspath

useTestNG() {
    suites("build/reports/tests/test/testng-failed.xml")
}
}

第二次运行任务尝试println file("build/reports/tests/test/testng-failed.xml").exists()true,但未运行失败的测试,并且跳过了任务:secondTry SKIPPED

Aftrer running task secondTry I got true for println file("build/reports/tests/test/testng-failed.xml").exists(), but failed tests are not run and task is skipped: secondTry SKIPPED

在这种情况下,有人能进行测试吗?

Does anyone experience in such cases, how to make tests run?

更新: 我已经尝试了一些修改任务,所以只需运行testng-failed.xml:

UPDATE: I've tried to modify task a bit, so just run testng-failed.xml:

task secondTry(type: Test) {
useTestNG() {
    useDefaultListeners = true
    reports.html.enabled = false
    options.suites("build/reports/tests/test/testng-failed.xml")
}
}

结果是,构建成功执行,包括secondTry任务,但失败的测试仍未运行.

As result, build is successfully executed, including secondTry task, but failed tests still are not run.

推荐答案

这可以通过TestNG的名为RetryAnalyzer的功能来实现.稍作调整,我们便可以告诉TestNG,在通过测试之前应重试多少次,以及什么样的异常/错误会触发重试失败的测试方法.

This can be achieved by a TestNG's feature called RetryAnalyzer. With few little tweaks, we can tell TestNG that how many times a test should get retried until it gets passed and what kind of exceptions/errors would trigger the retrying of the failed test methods.

这篇关于如何使用Gradle重新运行失败的TestNG测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆