Y.H Wong Y.H Wong - 1 year ago 161
Java Question

Is there a decent HTML Junit report plugin for Maven?

I find the

plug-in very unsuitable to my working style. I clean the project all the time and I don't want to spend 5 min to rebuild the whole site every time I want to look at the test report in my browser.

If I type
mvn surefire-report:report-only
, the generated report is too ugly and barely readable.

What I'm looking for is something like ant's JUnitReport task. Is there one available out there already?

Answer Source

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*):

            <junitreport todir="target/surefire-reports">
              <fileset dir="target/surefire-reports">
                <include name="**/*.xml"/>
              <report format="noframes" todir="target/surefire-reports"/>

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:

  1. Don't bind the AntRun plugin to the test phase, move the configuration outside the execution and call mvn antrun:run on the command line to generate the reports when wanted.

  2. or use the testFailureIgnore option of the test mojo and set it to true in the surefire plugin configuration:

  3. 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".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download