使用 Maven 命令在 Cucumber 中自动重新运行失败的测试用例

Rerun Failed test Cases in Cucumber Automatically using Maven Command

我没有使用 TestNG。我想自动使用 Maven 重新运行 失败的测试场景。

当我触发 mvn 时,应该 运行 测试并为所有失败的场景创建 rerun.txt。我能够在 运行 时间创建 rerun.txt,但不能自动 运行 失败场景。

testrunner.java

@CucumberOptions(
    features = "src/main/features/",
    plugin = {"pretty", "html:target/cucumber-report", "json:target/cucumber- 
    report/report.json", "rerun:target/rerun/rerun.txt"},
    tags = {"@test"},

pom.xml

       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <includes>
                 <include>**/*testrunner*.java</include>
           </includes>
         </configuration>
       </plugin>

此外,我知道我可以手动为 re运行 和 运行 创建另一个测试 运行ner。当我这样做并将其添加到 pom.xml 时。 testReRunner 有时 运行 没有在 rerun.txt 文件中创建失败的测试用例。

maven-surefire-plugin 有 built-in 重新运行失败测试的选项。

只需在surefire插件的<configuration>中添加<rerunFailingTestsCount>1</rerunFailingTestsCount>