Generating html surefire test html output during test phase
Asked Answered
H

1

24

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> 
Harpsichord answered 29/10, 2010 at 15:42 Comment(0)
V
29

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

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

Verde answered 29/10, 2010 at 23:32 Comment(3)
Thanks for your reply. I have no doubt your answer is correct, but for some reason it's not writing it to the disk. I'll have to do some more debugging when I get the chance..Harpsichord
mvn surefire-report:report is actually run under the site phase. This means a full rebuild (as site isn't part of the general lifecycle) if you are trying to generate reports for your release:deploy cycle's testing. But deploy:release may bump poms, and then things get a bit cranky :-)Kalagher
After mvn surefire-report:report-only don't forget to execute this mvn site -DgenerateReports=false to generate the required css/image/js files to make the report look prettyInchoation

© 2022 - 2024 — McMap. All rights reserved.