Maven surefire 插件输出测试摘要xml?

Maven surefire plugin output test summary xml?

我所在的项目分别使用 Surefire 和 Failsafe maven 插件进行 运行 单元和集成测试。 failsafe 的输出在 target/failsafe/failsafe-summary.xml 中生成测试 运行 的摘要。我想从 surefire 获得类似的 .xml 摘要报告,但是我似乎只能在那里为每个测试套件获得一个 xml 文件。

是否可以配置 surefire 来执行此操作?

Maven Surefire Report Plugin

适合我们,因为:

The Surefire Report Plugin parses the generated TEST-*.xml files under ${basedir}/target/surefire-reports and renders them using DOXIA, which creates the web interface version of the test results.

根据https://maven.apache.org/surefire/maven-surefire-report-plugin/usage.html,我们可以:

Generate the Report as Part of Project Reports

To generate the Surefire report as part of the site generation, add the following in the <reporting> section of your POM:

<project>
    ...
    <reporting>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-report-plugin</artifactId>
          <version>3.0.0-M5</version>
        </plugin>
      </plugins>
    </reporting>
    ...
  </project>

When mvn site is invoked, the report will automatically be included in the Project Reports menu as shown in the figure below.

...或

Generate the Report in a Standalone Fashion

The plugin can also generate the report using its standalone goal:

mvn surefire-report:report A HTML report should be generated in ${basedir}/target/site/surefire-report.html.

欢迎光临! ;)

Is it possible to configure surefire to do this?

(创建 1 个报告 file/run 而不是 1 个/测试套件)

不,不是没有自定义 surefire/surefire-report 插件。

因为(surefire-plugin:test)唯一的(up-to-date)“输出相关”配置选项是:

  • 编码
  • redirectTestOutputToFile
  • reportFormat(默认 - “brief”,或者 - “plain”(*.txt 文件))
  • reportNameSuffix
  • 报告目录

而 surefire-report 插件的唯一目的是生成 maven 报告 (html!)。


对于这种特殊需要,我建议使用自定义脚本或 (maven) 插件(基于上述之一 - 它们是开源的)。您还可以通过将所有测试 classes/suits 合并为一个来尝试“从源头解决问题”!? :)