【发布时间】:2018-07-17 13:16:31
【问题描述】:
我怎样才能让失败的场景在失败时自动再次运行?
这是我在做什么的一些线索:
- 在运行时通过 cucumber-testng.xml 文件从命令行传递 TestRunner 类。
- 场景失败后我可以看到 rerun.txt 文件,
feature/GM/TK/payment.feature:71(指向失败的场景)但失败的场景不会自动重新运行。
“TestRunner”java 文件
@RunWith(Cucumber.class)
@CucumberOptions(strict = true,
features = { "src/test/resources/" }, //feature file location
glue = { "com/test/stepdefs", "com.test.cucumber.hooks" }, //hooks and stepdef location
plugin = { "json:target/cucumber-report-composite.json", "pretty", "rerun:target/rerun.txt"}
)
public class CucumberTestRunner extends AbstractTestNGCucumberTests
{
}
从 rerun.txt 文件重新运行的“RunFailedTest”类
@RunWith(Cucumber.class)
@CucumberOptions(
strict = false,
features = { "@target/rerun.txt" }, //rerun location
glue = { "com/test/stepdefs", "com.test.cucumber.hooks" }, //hooks and stepdef location
plugin = {"pretty", "html:target/site/cucumber-pretty", "json:target/cucumber.json"}
)
class RunFailedTest
{
}
【问题讨论】:
-
您是希望动态识别失败的测试以重新运行,还是只是手动将它们分离到另一个文件中?看起来像后者,在这种情况下,您应该考虑使用 tags 并在 CucumberOptions 中指定它们。
-
jsheeran 是的,动态失败的场景存储在 rerun.txt 中,并在第一次执行完成后立即自动运行,因为失败发生
-
为什么 CucumberTestRunner 中既有 junit 又有 testng?并且只有在 RunFailedTest 中的 junit?你是如何进行测试的?
标签: testing cucumber-java