Cucumber-java rerun fail 只执行失败的测试
Posted
技术标签:
【中文标题】Cucumber-java rerun fail 只执行失败的测试【英文标题】:Cucumber-java rerun fail to execute only the failed test 【发布时间】:2022-01-18 11:56:17 【问题描述】:我已经构建了一个 cucumber + java + selenium 项目,我想在我的管道中添加重新运行阶段。在运行器 AllTestRunner.java 中使用 @rerun 插件我只能创建一个 rerun.txt失败的测试,并使用 maven-surefire-plugin,我创建了第二个运行器 FailedRunner.java 用于自动执行,仅失败的测试。
问题是 FailedRunner.java 不只执行失败的测试,而是所有在 AllTestRunner.java 中配置为特征文件的测试。 知道为什么会这样吗? 这是我的 pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/*Runner.java</include>
</includes>
</configuration>
<!-- <configuration>-->
<!-- <parallel>methods</parallel>-->
<!-- <threadCount>3</threadCount>-->
<!-- <testFailureIgnore>true</testFailureIgnore>-->
<!-- </configuration>-->
</plugin>
和 ExecuteRunner.java
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/com/bdd/jenkins",
glue = "com.bdd.helpers", "com.bdd.steps",
tags= "not @Fail", //not @ignore
plugin = "pretty", "html:target/cucumber", "json:target/cucumber.json", "rerun:target/rerun.txt"
)
public class ExecuteRunner
和 FailedRunner.java
@CucumberOptions(features = "@target/rerun.txt",
glue = "com.bdd.helpers", "com.bdd.steps",
plugin = "pretty","html:target/cucumberRerun", "json:target/cucumberRerun.json"
)
public class FailedRunner
在日志中我看到以下内容:
Running com.pollfish.bdd.runners.ExecuteRunner
20:21:39,519 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
20:21:39,519 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
2
....
@batch1 @Test1
Scenario: Create questionnaire adding targeting and send for approval # src/test/resources/com/bdd/jenkins/migrated/CreateSurvey.feature:22
20:21:41.179 [main] INFO com.bdd.steps.Hooks - Every test start from home page.
2
和
Running com.pollfish.bdd.runners.FailedRunner
02:41:09.170 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
...
@batch1 @Test1
Scenario: Create questionnaire adding targeting and send for approval # src/test/resources/com/bdd/jenkins/migrated/CreateSurvey.feature:22
02:41:09.283 [main] INFO com.bdd.steps.Hooks - Every test start from home page.
并且rerun.txt包含
file:src/test/resources/com/bdd/jenkins/migrated/QuestionnaireADL.feature:6:44:54:84
file:src/test/resources/com/bdd/jenkins/migrated/Recurring.feature:12:43:60
【问题讨论】:
【参考方案1】:我找到了罪魁祸首。因为我通过 maven 构建工具运行它,使用以下命令:mvn clean test -Dcucumber.features=src/test/resources/features
,它看起来在 FailedRunner.java 即使我们设置了特殊的重新运行功能文件,并且因为命令行参数覆盖了定义的类参数,再次执行所有测试。
像设计一样工作,我会说
【讨论】:
以上是关于Cucumber-java rerun fail 只执行失败的测试的主要内容,如果未能解决你的问题,请参考以下文章