问题描述
我有一个 Cucumber 项目,它同时使用了 Junit 和 Maven。我还添加了 Maven Surefire Plugin 以启用重新运行和并行执行。 pom xml 中的那部分如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<threadCount>3</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
<useUnlimitedThreads>false</useUnlimitedThreads>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<includes>
<include>**/*Cucumber.java</include>
</includes>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
但是当执行 rerun 时,会生成 junit xml 文件,其中包含 rerun 时运行的场景。举个例子,如果我执行 61 个场景并且 61 个场景中的 1 个在重新运行时失败,则 junit xml 文件只包含 1 个场景。在上次重新运行之前通过的 60 个场景不会添加到 xml 结果中。 Xml 文件是在我下面给出的路径中生成的:
junit:target/cucumber-reports/cucumber.xml
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(strict = true,features = { "src/test/resources/features" },glue = {
"stepDeFinitions" },monochrome = true,tags = "not @ignore",plugin = { "pretty","html:target/cucumber-html-reports","json:target/cucumber-reports/cucumber.json","junit:target/cucumber-reports/cucumber.xml","json:target/cucumber.json","com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" },dryRun = false)
public class TestRunnerCucumber {
}
示例运行结果:
示例运行的 XML 结果:
如何将第一次运行时传递的场景添加到 junit xml 结果中?
解决方法
您尝试做的事情是不可能的。
您正在使用 Surefire 重新运行测试。从 Cucumber 再次运行测试的角度来看,与使用较少的测试再次运行 Cucumber 相同。这意味着第一次运行的输出将替换为重新运行的结果。
只有 Surefire 知道测试已重新运行。因此,在使用 Surefires 重新运行功能时,您必须依赖 Surefires 报告。它们也位于 target
文件夹中。