在测试阶段生成html surefire测试html输出 [英] Generating html surefire test html output during test phase

查看:116
本文介绍了在测试阶段生成html surefire测试html输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否是一个简单的问题,但是我希望surefire在测试阶段生成html格式的输出文件(除了xml和txt格式的输出文件).

我试图通过为build> surefire添加一个"executions"条目来实现这一点.这是正确的位置吗?如果是这样,我做错了吗?

<build>
  ..
  <plugins>
    ..
    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <outputDirectory>site</outputDirectory>

                </configuration>
                <executions>
                    <execution>
                        <id>during-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin> 

解决方案

我希望surefire在测试阶段生成html格式的输出文件(除了xml和txt格式的输出文件).

最简单的方法(不运行site)可能只是调用:

mvn surefire-report:report

这将在生成报告之前运行测试(但是结果不是那么好,因为不会生成CSS,因此您必须运行site).

我试图通过为build> surefire添加一个"executions"条目来实现这一点.这是正确的位置吗?如果是这样,我做错了吗?

如果您真的想将surefire-report插件绑定到test阶段,我的建议是使用report-only目标(因为它不会重新运行测试,请参见是否有适用的HTML Junit报告插件Maven?

I'm not sure if this is a simple question or not, but I'd like surefire to generate html formatted output files(in addition to the xml and txt formatted output files) during the test phase.

I've tried to make this happen by adding an 'executions' entry for build>surefire. Is this the correct location for this? If so, am I doing it wrong?

<build>
  ..
  <plugins>
    ..
    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <outputDirectory>site</outputDirectory>

                </configuration>
                <executions>
                    <execution>
                        <id>during-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin> 

解决方案

I'd like surefire to generate html formatted output files (in addition to the xml and txt formatted output files) during the test phase.

The easiest way (without running site) would be probably to just invoke:

mvn surefire-report:report

This will run the tests prior to generating the report (but the result is not that nice because the CSS won't be generated, you'd have to run site for that).

I've tried to make this happen by adding an 'executions' entry for build>surefire. Is this the correct location for this? If so, am I doing it wrong?

If you really want to bind the surefire-report plugin to the test phase, my suggestion would be to use the report-only goal (because it won't rerun the tests, see SUREFIRE-257), like this:

<plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-report-plugin</artifactId>
  <version>2.6</version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals>
        <goal>report-only</goal>
      </goals>
    </execution>
  </executions>
</plugin>

As a side note, generating the report as part of the site:

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.6</version>
        <reportSets>
          <reportSet>
            <reports>
              <report>report-only</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

And running

mvn test site

doesn't seem to be that much slower (I was using Maven 3, with this report only) and produces a much nicer result. This might not be an option if you have a complex site setup though (at least not without making things more complex by introducing profiles).

Related question

这篇关于在测试阶段生成html surefire测试html输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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