我的 POM 目前看起来像,
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>2.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>ExecuteAutomation</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
这确实会生成报告,但仅包含最后一个功能。我有多个跑步者,所以我想弄清楚:
一个。如何将多个 JSON 组合成一个报告或
乙。如何在每次测试完成时附加到一个 JSON 文件?
这两个似乎都是可行的解决方案,尽管我更喜欢 A,因为看起来我的 pom.xml 中只缺少一行来这样做,因为我目前已经生成了多个 JSON 文件
问题是正在使用的版本(即 2.8)不支持多个 JSON 文件。
解决方法是:
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>4.5.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>ExecuteAutomation</projectName>
<inputDirectory>${project.build.directory}/jsonReports</inputDirectory>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
阅读更多内容https://github.com/damianszczepanik/maven-cucumber-reporting
如果您可以运行 bash 命令并且机器上可能有 jq,也许可以尝试在不同名称的文件中生成报告,然后使用 jq 将它们合并回一个文件
我做了类似的事情,尽管我不并行运行,也不依赖任何插件,我使用 surefire 插件运行
免责声明:我没有用 --format 测试报告名称覆盖,所以这部分对您来说可能有所不同,但想法是一样的
mvn test -Dcucumber.options="--format=json:target/cucumber_test1.json"
mvn test -Dcucumber.options="--format=json:target/cucumber_test2.json"
...
jq -s '[.[][]]' target/cucumber_*.json > target/cucumber.json
我只是想补充一下之前的回答,
你可能有这两种行为,当你看到一个 fetarue 在获得通过状态后被重新执行了多少次时,附加 json 文件以完成,或者只是获得最终报告,其中功能在重新运行后仅以最新状态出现一次。
我能够在重新运行后合并报告的结果,只需使用
这里更详细,在关于插件评论的自述文件中: https://github.com/damianszczepanik/maven-cucumber-reporting
希望有帮助。