我用黄瓜为我的测试。 我如何只重新运行失败的测试?
Answer 1:
与重播格式运行黄瓜:
cucumber -f rerun --out rerun.txt
它将所有的输出位置失败情景此文件。
然后,你可以使用它们重新运行
cucumber @rerun.txt
Answer 2:
这里是我的简单利落的解决方案。
第1步 :写你的黄瓜的java文件作为下面提到rerun:target/rerun.txt
。 黄瓜在写入失败的情况行号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步运行该文件
Answer 3:
你为了使用@目标至少需要1.2.0版本/ rerun.txt新功能。 之后,刚刚创建运行在年底和使用此文件亚军。 此外,如果您使用的詹金斯,你可以把标签上的随机故障功能,因此,除非是经过两次跑构建不失败。
文章来源: How to rerun the failed scenarios using Cucumber?