4

How can i generate surefire reports in the maven's default lifecycle. We have jobs setup in teamcity with goals as

mvn clean install -Pprod

This job runs all the junits, i want to create HTML report of all the tests running in the project. I came across the sure-fire-reports plugin but it generates the report only in site phase it does not generates the report during the default clean install phase.

Can one please help how can i generate report default lifecycle

I tried including the surefire-reports plugin, in test phase as below but doesnot not works

<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>
Ambuj Jauhari
  • 1,187
  • 4
  • 26
  • 46
  • What about http://maven.apache.org/surefire/maven-surefire-report-plugin/ ? – khmarbaise Aug 31 '16 at 12:03
  • I checked the usage page for this plugin it states - > "When mvn site is invoked, the report will automatically be included in the Project Reports menu" or i need to use mvn surefire-report:report but nothing i can find where report will be generated on mvn clean install, as per my understanding site phase is not part of maven's default lifecycle. – Ambuj Jauhari Aug 31 '16 at 12:17
  • But you can bind the plugin to a different phase if you like – khmarbaise Aug 31 '16 at 12:34
  • Have you thought of transforming the XML reports produced by maven-surefire-plugin? You could do it just after they are produced. For example, in the prepare-package phase. – Little Santi Aug 31 '16 at 12:54
  • @khmarbaise updates the question i did tried binding to test phase but does not works for me – Ambuj Jauhari Aug 31 '16 at 13:18
  • @LittleSanti I will try transforming XML reports to HTML but will it work in case of multi - module project and from my parent project i would like to browse the reports of child projects ? – Ambuj Jauhari Aug 31 '16 at 13:19
  • @AmbujJauhari Hum... This sounds to me much as a **site**, actually. Why can't you execute the `site` lifecycle? – Little Santi Aug 31 '16 at 13:25
  • @LittleSanti I am not allowed to change teamcity :D :P also as per my knowledge the site phase will not create the artifacts or jars and install to maven repo since once the jars are created we have a second step to zip the jars and throw them at a different server. – Ambuj Jauhari Aug 31 '16 at 13:28
  • @AmbujJauhari I see, but it's only execute "mvn clean install site". OK, if you can't, you can't. I'll post my answer more explained. – Little Santi Aug 31 '16 at 13:32
  • Possible duplicate of [Generating html surefire test html output during test phase](https://stackoverflow.com/questions/4053474/generating-html-surefire-test-html-output-during-test-phase) – Vadzim Sep 14 '19 at 09:21

1 Answers1

2

If you need the very report generated by maven-surefire-report-plugin, I see no other way than execute mvn site, because a report is executed only within the site phase of the build lifecycle.

Instead, if you just need an HTML-readable report, I'd suggest you this walk-around:

  • Take advantage of the XML files generated by the maven-surefire-plugin in the target/surefire-reports directory.
  • Code your own transformation sheet (XSL) to transform them to the desired HTML format.
  • In the pom, set a transformation in the next phase (for example, prepare-package) through the xml-maven-plugin.

If you put the XSL in the parent project and set this transformation in the parent pom, all the submodule projects should inherit it and produce the HTML reports during the corresponding build.

And last: How to browse the child HTML reports from the parent project? Hum... I'd say to code an Ant script to browse all the submodules and list the HTML files and produce an HTML index with them. This script should be executed only from the parent project.

Little Santi
  • 8,563
  • 2
  • 18
  • 46