Is there a decent HTML Junit report plugin for Maven?
This is what I do:
# Run tests and generate .xml reports
mvn test
# Convert .xml reports into .html report, but without the CSS or images
mvn surefire-report:report-only
# Put the CSS and images where they need to be without the rest of the
# time-consuming stuff
mvn site -DgenerateReports=false
go to target/site/surefire-report.html for the report.
After tests run, the rest of the two run in about 3.5 seconds for me.
Hope that helps. Enjoy!
Create a new maven run configuration and with goal =>
surefire-report:report site -DgenerateReports=false
This can help you to have a better report view with css.
Indeed, generating the whole site at each build is clearly not an option. But the problem is that mvn surefire-report:report-only
doesn't create the the css/*.css files, hence the ugly result. This is logged in SUREFIRE-616 (doesn't mean something will happen though). Personally, I don't use HTML reports that much so I can live with that but that's not a good answer so here is a workaround based on the ant task (*sigh*):
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>test-reports</id>
<phase>test</phase>
<configuration>
<tasks>
<junitreport todir="target/surefire-reports">
<fileset dir="target/surefire-reports">
<include name="**/*.xml"/>
</fileset>
<report format="noframes" todir="target/surefire-reports"/>
</junitreport>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
</plugin>
Update: My initial idea was to run the Maven AntRun plugin "on demand" to generate the reports... but that's not what I posted, I bound it to the test
phase... But I didn't think about the case of failed tests (that would stop the build and prevent the execution of the AntRun plugin). So, either:
Don't bind the AntRun plugin to the
test
phase, move the configuration outside theexecution
and callmvn antrun:run
on the command line to generate the reports when wanted.or use the
testFailureIgnore
option of the test mojo and set it to true in the surefire plugin configuration:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin>
or set this expression from the command line using the -D parameter:
$ mvn test -Dmaven.test.failure.ignore=true
I think that Option #1 is the best option, you don't necessarily want to generate the reports (especially when the test passes) and generate them systematically may slow down the build on the long term. I'd generate them "on demand".
Thanks for Pascal, I've found an improved solution to do what I want to do:
<plugin>
<!-- Extended Maven antrun plugin -->
<!-- https://maven-antrun-extended-plugin.dev.java.net/ -->
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<executions>
<execution>
<id>test-reports</id>
<phase>test</phase>
<configuration>
<tasks>
<junitreport todir="target/surefire-reports">
<fileset dir="target/surefire-reports">
<include name="**/*.xml"/>
</fileset>
<report format="noframes" todir="target/surefire-reports"/>
</junitreport>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-trax</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
</plugin>
This version uses a newer version of ant and best of all. However, I still haven't found a way to generate a test report when tests fail. How should I do that?