21

我不确定这是否是一个简单的问题,但我希望在测试阶段生成 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> 
4

1 回答 1

25

我希望在测试阶段生成 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,仅使用此报告)并产生了更好的结果。如果您有一个复杂的站点设置,这可能不是一个选项(至少不会通过引入配置文件使事情变得更复杂)。

相关问题

于 2010-10-29T23:32:16.477 回答