我有 UI 测试项目和一个具有相同技术堆栈(JAVA1.8、Cucumber-JVM、JUnit、Maven)的 API 测试项目,这两个项目都向我展示了这个问题。可能是因为两者都存在相同的依赖项。
我使用了 Flaky 测试重新运行机制,使用 maven-surefire-plugin 内置功能<rerunFailingTestsCount>1</rerunFailingTestsCount>
。另外,我基于<groupId>io.cucumber</groupId>
而不是添加了黄瓜依赖项<groupId>info.cukes</groupId>
。这两个都有自己版本的 cucumber-java 和 cucumber-jvm 依赖项。
我的 POM.XML 看起来像这样。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<rerunFailingTestsCount>1</rerunFailingTestsCount>
</configuration>
<executions>
<execution>
<id>acceptance-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/*Runner.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>2.4.0</version>
<type>pom</type>
</dependency>
仅 RUNNER 文件代码
@RunWith(Cucumber.class)
@ContextConfiguration(locations = {"file:/src/test/resources/spring-config.xml"})
@CucumberOptions(
glue = "com.test.uitest",
features = "classpath:cucumber",
tags = {"~@ignore","@ui_home"},
monochrome = true,
plugin = {"pretty", "html:target/cucumber-reports",
"json:target/cucumber-reports/cucumber.json",
"rerun:target/rerun.txt"} //Creates a text file with failed scenarios
)
public class AllTestsRunner {
}
现在显然,我需要另一个运行程序,其中包含以下代码(根据 StackOverflow 上的其他论坛和线程)
@RunWith(Cucumber.class)
@CucumberOptions(
monochrome = true,
glue = "com.test.uitest",
features = "@target/rerun.txt", //Cucumber picks the failed scenarios from this file
format = {"pretty", "html:target/rerun-reports",
"json:target/cucumber-reports/rerun-report.json"}
)
public class FailedTestsRunner {
}
但是我不需要这个第二个跑步者,因为重新运行机制非常出色,只有一个跑步者在上面。甚至,不需要在 1st runner 中生成 rerun.txt 文件。maven-surefire 插件(v_2.21.0)中的内置机制以及 io.cucumber v_2.4.0 可以完美运行,如果在第一次执行期间出现任何场景失败,它会自动重新运行,而不会将其记录在 rerun.txt 文件中。
##问题是##
我的功能文件中有 5 个场景。如果他们都在第一次运行中通过。它成功生成了带有 cucumber.json 报告的报告,显示了所有 5 个场景。但是,如果(比如说)5 个场景中有 2 个失败,并且这些场景在重新运行机制中自动执行,那么 cucumber.json 报告文件只记录这两个场景的结果,而不是所有 5 个场景的结果。如果这 2 个场景在重新运行中通过,则整体构建通过;如果这 2 个场景失败,则整体构建失败。这是正确的,但我的问题是 cucumber.json 被重新运行机制覆盖。我曾尝试使用maven-cucumber-reporting
插件 v_3.16.0 但它实际上读取 cucumber.json 文件本身,因此无法解决我的问题。任何帮助,将不胜感激。