【问题标题】:Generating html surefire test html output during test phase在测试阶段生成 html surefire 测试 html 输出
【发布时间】:2010-10-29 15:42:06
【问题描述】:

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

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

<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> 

【问题讨论】:

    标签: maven-2 surefire


    【解决方案1】:

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

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

    mvn surefire-report:report
    

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

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

    如果你真的想将surefire-report 插件绑定到test 阶段,我的建议是使用report-only 目标(因为它不会重新运行测试,请参阅SUREFIRE-257),就像这样:

    <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>
    

    附带说明,生成报告作为网站的一部分:

      <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>
    

    然后运行

    mvn test site
    

    似乎并没有那么慢(我使用的是 Maven 3,仅使用此报告)并且产生了更好的结果。如果您有一个复杂的站点设置,这可能不是一个选项(至少在不通过引入配置文件使事情变得更复杂的情况下)。

    相关问题

    【讨论】:

    • 感谢您的回复。我毫不怀疑您的答案是正确的,但由于某种原因它没有将其写入磁盘。当我有机会时,我将不得不做更多的调试..
    • mvn surefire-report:report 实际上是在站点阶段下运行的。如果您尝试为您的发布:部署周期的测试生成报告,这意味着完全重建(因为站点不是一般生命周期的一部分)。但是 deploy:release 可能会碰到 pom,然后事情变得有点古怪:-)
    • mvn surefire-report:report-only之后别忘了执行这个mvn site -DgenerateReports=false来生成所需的css/image/js文件让报表看起来很漂亮
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2021-04-05
    相关资源
    最近更新 更多