提问者:小点点

如何使用Cucumber重新运行失败的场景?


我正在使用Cucumber进行测试。如何仅重新运行失败的测试?


共3个答案

匿名用户

使用重跑格式化程序运行Cucumber:

cucumber -f rerun --out rerun.txt

它会将所有失败方案的位置输出到此文件。

然后您可以通过使用

cucumber @rerun.txt

匿名用户

这是我简单明了的解决方案。

第1步:使用rerun: target/rerun.txt编写cucumberjava文件。Cucumber将失败场景的行号写入rerun.txt中,如下所示。

features/MyScenaios.feature:25
features/MyScenaios.feature:45

稍后我们可以在步骤2中使用这个文件。将此文件命名为MyScenarioTests.java。这是运行标记场景的主文件。如果您的场景有失败的测试用例,MyScenarioTests.java将在目标目录下写入/标记它们rerun. txt

@RunWith(Cucumber.class)
@CucumberOptions(
    monochrome = true,
    features = "classpath:features",
    plugin = {"pretty", "html:target/cucumber-reports",
              "json:target/cucumber.json",
              "rerun:target/rerun.txt"} //Creates a text file with failed scenarios
              ,tags = "@mytag"
           )
public class MyScenarioTests   {

}

第2步:创建另一个场景文件,如下所示。让我们说这是FailedScenarios.java。每当您注意到任何失败的场景时,运行此文件。该文件将使用target/rerun. txt作为运行场景的输入。

@RunWith(Cucumber.class)
@CucumberOptions(
    monochrome = true,
    features = "@target/rerun.txt", //Cucumber picks the failed scenarios from this file 
    format = {"pretty", "html:target/site/cucumber-pretty",
            "json:target/cucumber.json"}
  )
public class FailedScenarios {

}

每次如果您注意到任何失败的场景,请在步骤2中运行文件

匿名用户

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'json:target/cucumber-reports/json/cucumber.json',
                    '--plugin', "rerun:target/rerun.txt",
                    '--glue', 'steps',
                    'src/test/resources']
        }
    }
}

task cucumberRerunFailed() {
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'json:target/cucumber-reports/json/cucumber.json',
                    '@target/rerun.txt']
        }
    }
}