# TestNG rerun failed tests

**URL:** https://discuss.gradle.org/t/testng-rerun-failed-tests/7004
**Category:** Old Forum Archive
**Created:** [May 15, 2012, 4:09pm UTC](https://discuss.gradle.org/t/testng-rerun-failed-tests/7004 "2012-05-15T16:09:00Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)
#### Post date: [May 16, 2012, 11:04am UTC](https://discuss.gradle.org/t/testng-rerun-failed-tests/7004/7 "2012-05-16T11:04:00Z")

</div>

hello federico, the configuration for rerunning failing tests in a second test task can look like this:

```gradle
test{
 useTestNG()
 ignoreFailures = true
 }
  task secondTry(type:Test){
  onlyIf{
   file("build/reports/tests/testng-failed.xml").exists()
   }
    dependsOn test
    testClassesDir = sourceSets.test.output.classesDir
  classpath = sourceSets.test.runtimeClasspath
  testSrcDirs = sourceSets.test.java.srcDirs as List
     testReportDir = file("$buildDir/reports/secondTry")
        useTestNG(){
  suites("build/reports/tests/testng-failed.xml")
  }
 }
   task allTests(dependsOn: tasks.withType(Test))

```

just run “gradle alltests” and if all tests pass on the first try, the secondTry task is skipped. If the test task has failed tests, the secondTry test task retries them.

Have a look at the DSL reference of the Test task for details ([http://gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.Test.html](http://gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.Test.html))

regards, René

---

_[View the full topic](https://discuss.gradle.org/t/testng-rerun-failed-tests/7004)._
