Jugi
Jugi

Reputation: 1254

Customized html report name in JUnitReport task

I am using JunitReport task for generating junit report in HTML format using maven.

I have added the below items in pom.xml to generate the test report in HTML

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

The html report name is always displayed as junit-noframes.html. Since i generate more html reports, every html report is getting generated with same name as junit-noframes.html. I want to give custom html report name.

How to change the html report name ? I dont find any options for this.

Upvotes: 1

Views: 1790

Answers (1)

Abel
Abel

Reputation: 57169

The documentation says:

The noframes format does not use redirecting and generates one file called junit-noframes.html.

And doesn't offer a way around that. However, you can use parameters just like with ANT, so the following would work:

<report format="noframes" todir="${report.location}" /> 

There are several ways of setting the parameters, either from the commandline, an environment variable, or a build.properties file.

It seems to me that this element does not allow you to change the output filename of the XSLT transformation, however, you could force the output filename if you can write a custom XSLT stylesheet and use an extension function, or if you can configure ANT to use an XSLT 2.0 processor and use xsl:result-document. This seems a lot of trouble to fix this, though.

If it suffices in your situation to place them in different directories, then that is the easy way out.


Another solution as proposed by Suntaragali Qa, you can solve it by moving the file to a new name with a timestamp.

Add this:

<tstamp>
    <format property="timestamp" pattern="yyyyMMddHHmmss" />
</tstamp>

And change this:

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

<move 
    file="target/surefire-reports/html/junit-noframes.html" 
    tofile="target/surefire-reports/html/junit-report-${timestamp}.html" />

I think this second solution is much easier to implement and uses standard ANT syntax. See the link for more info on how to do this.

Upvotes: 1

Related Questions