Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Report for JUNIT by ANT

Tags:

junit

ant

How can I generate HTML reports from JUnit using Ant when there are test failures?

The reports are generated when there are no failures.

Also, how can we define our own XSLT for the report generation?

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant Example" default="all" basedir=".">
    <property name="project_name" value="junitSamples" />
    <property name="src" location="src" />
    <property name="build" location="build/classes" />
    <property name="lib" location="lib" />
    <property name="reports" location="reports" />

    <target name="init" depends="clean">
        <mkdir dir="${build}" />
        <mkdir dir="${lib}" />
        <mkdir dir="${reports}" />
        <mkdir dir="${reports}/raw/" />
        <mkdir dir="${reports}/html/" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="${src}" destdir="${build}" description="compile the source code ">
            <classpath>
                <fileset dir="lib">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>
        </javac>
    </target>

    <target name="clean">
        <delete dir="build" />
        <delete dir="${reports}" />
    </target>

    <target name="run-tests" depends="compile">
        <junit printsummary="yes" haltonfailure="yes" showoutput="yes">
            <classpath>
                <pathelement path="${build}" />
                <fileset dir="lib">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>

            <batchtest fork="yes" todir="${reports}/raw/">
                <formatter type="xml" />
                <fileset dir="${src}">
                    <include name="**/*Test*.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="test" depends="run-tests">
        <junitreport todir="${reports}">
            <fileset dir="${reports}/raw/">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="noframes" todir="${reports}\html\" />
        </junitreport>
    </target>

    <target name="all" depends="clean, test" />
</project>
like image 896
user1753210 Avatar asked Oct 07 '22 06:10

user1753210


1 Answers

To specify your own stylesheets, use the "styledir" attribute:

<report styledir="${resources}/junit" format="..." todir="..." />

As noted, you must use the "junit-noframes.xsl" stylesheet name.

JUnit report docs.

like image 199
Dave Newton Avatar answered Oct 10 '22 08:10

Dave Newton