如何使用Cucumber重新运行失败的场景?
我正在使用黄瓜进行testing。 如何仅重新运行失败的testing?
重新运行格式化程序运行黄瓜:
cucumber -f rerun --out rerun.txt 它将输出所有失败scheme的位置到这个文件。
然后你可以通过使用重新运行它们
 cucumber @rerun.txt 
这是我简单而整洁的解决scheme。
  第一步 :用rerun:target/rerun.txt写下你的黄瓜java文件。 黄瓜在rerun.txt写入失败的场景行数,如下所示。 
 features/MyScenaios.feature:25 features/MyScenaios.feature:45 
稍后我们可以在步骤2中使用这个文件
 @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步:创build另一个场景文件,如下所示。 我们假设这是FailedScenarios.java 
 @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中运行该文件
您至less需要1.2.0版才能使用@target / rerun.txt新function。 之后,只需创build一个最后运行的runner并使用这个文件。 另外,如果您使用的是Jenkins,则可以在随机故障function上放置一个标签,以便构build不会失败,除非运行两次。