0

I want to automatically retry failed tests to improve the reliability of my tests similar to the TestRule found within Junit I want the flexibility to insert logic around the tests so I can implement a retry loop:

  • I’m using Cucumber-JVM and need a solution involving Java or Gradle

  • I have tried the following cucumber options via Gradle javaexec:

    //--format pretty --format rerun --out tmp/rerun.txt

    //--format rerun --out C:\Desktop\failed.txt

Currently I am in the process of trying this via the RunCukesTest.java.

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;


/**
 *  String         dotcucumber 
    boolean dryRun 
    String[]    features 
    String[]    format 
    String[]    glue 
    boolean monochrome 
    String[]    name
    Specify a patternfilter for features or scenarios
    SnippetType snippets 
    boolean strict 
    String[]    tags 
 * 
 */


@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true)
public class RunCukesTest {
}
Alex Wittig
  • 2,800
  • 1
  • 33
  • 42

1 Answers1

0

Pulled Dervis suleyman's answer out of the question:

After looking around and trying a few things, I finally settled for a quick and dirty fix. Here is my solution:

task cucumber() {
dependsOn assemble, compileTestJava
doLast {
    javaexec {
        main = "cucumber.api.cli.Main"
        classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
        args = ['-f', 'rerun:rerun.txt','--glue', 'org.test.cucumber', 'src/test/resources']
    }
}
}

task cucumberRerun() {
dependsOn assemble, compileTestJava
doLast {
    def file1 = new File('rerun.txt')
    for (int i=0;i<file1.getText().split(" ").length;i++) {
        println file1.getText().split(" ")[i]
        try {
            javaexec {
                main = "cucumber.api.cli.Main"
                classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
                args = ['-f','html:target'+i,'--glue', 'org.test.cucumber', 'src/test/resources/'+file1.getText().split(" ")[i]]
            }
        } catch (Exception e) {

        }
    }
}
}

cucumber.finalizedBy cucumberRerun
Alex Wittig
  • 2,800
  • 1
  • 33
  • 42