是否有适用于 Maven 的体面的 HTML Junit 报告插件? [英] Is there a decent HTML Junit report plugin for Maven?

查看:21
本文介绍了是否有适用于 Maven 的体面的 HTML Junit 报告插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 surefire-report 插件非常不适合我的工作方式.我一直在清理项目,我不想每次想在浏览器中查看测试报告时都花费 5 分钟来重建整个站点.

I find the surefire-report plug-in very unsuitable to my working style. I clean the project all the time and I don't want to spend 5 min to rebuild the whole site every time I want to look at the test report in my browser.

如果我输入mvn surefire-report:report-only,生成的报告太难看,几乎不可读.

If I type mvn surefire-report:report-only, the generated report is too ugly and barely readable.

我正在寻找类似于 ant 的 JUnitReport 任务.有没有可用的?

What I'm looking for is something like ant's JUnitReport task. Is there one available out there already?

推荐答案

确实,在每次构建时生成整个站点显然不是一种选择.但问题是 mvn surefire-report:report-only 不会创建 css/*.css 文件,因此结果很难看.这已记录在 SUREFIRE-616(不过并不意味着会发生什么).就我个人而言,我不怎么使用 HTML 报告,所以我可以接受,但这不是一个好的答案,所以这里有一个基于 ant 任务的解决方法 (*sigh*):

Indeed, generating the whole site at each build is clearly not an option. But the problem is that mvn surefire-report:report-only doesn't create the the css/*.css files, hence the ugly result. This is logged in SUREFIRE-616 (doesn't mean something will happen though). Personally, I don't use HTML reports that much so I can live with that but that's not a good answer so here is a workaround based on the ant task (*sigh*):

  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>test-reports</id>
        <phase>test</phase>
        <configuration>
          <tasks>
            <junitreport todir="target/surefire-reports">
              <fileset dir="target/surefire-reports">
                <include name="**/*.xml"/>
              </fileset>
              <report format="noframes" todir="target/surefire-reports"/>
            </junitreport>
          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>ant</groupId>
        <artifactId>ant-junit</artifactId>
        <version>1.6.2</version>
      </dependency>
    </dependencies>
  </plugin>

更新:我最初的想法是按需"运行 Maven AntRun 插件以生成报告……但这不是我发布的内容,我将其绑定到 test 阶段...但我没有考虑测试失败的情况(这会停止构建并阻止 AntRun 插件的执行).所以,要么:

Update: My initial idea was to run the Maven AntRun plugin "on demand" to generate the reports... but that's not what I posted, I bound it to the test phase... But I didn't think about the case of failed tests (that would stop the build and prevent the execution of the AntRun plugin). So, either:

  1. 不要将 AntRun 插件绑定到 test 阶段,将配置移到 execution 之外并调用 mvn antrun:run 在命令行上根据需要生成报告.

  1. Don't bind the AntRun plugin to the test phase, move the configuration outside the execution and call mvn antrun:run on the command line to generate the reports when wanted.

或使用testFailureIgnore 测试 mojo 选项并在surefire插件配置中将其设置为true:

or use the testFailureIgnore option of the test mojo and set it to true in the surefire plugin configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <testFailureIgnore>true</testFailureIgnore>
  </configuration>
</plugin>

  • 或使用 -D 参数从命令行设置此表达式:

  • or set this expression from the command line using the -D parameter:

    $ mvn test -Dmaven.test.failure.ignore=true
    

  • 我认为选项 #1 是最好的选择,您不一定要生成报告(尤其是当测试通过时)并系统地生成它们可能会降低长期构建的速度.我会按需"生成它们.

    I think that Option #1 is the best option, you don't necessarily want to generate the reports (especially when the test passes) and generate them systematically may slow down the build on the long term. I'd generate them "on demand".

    这篇关于是否有适用于 Maven 的体面的 HTML Junit 报告插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆