title: HTML Report for JUNIT by ANT
body: <p>How can I generate HTML reports from JUnit using Ant when there are test failures?</p>
  
  <p>The reports are generated when there are no failures.</p>
  
  <p>Also, how can we define our own XSLT for the report generation?</p>
  
  <p><strong>build.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project name="Ant Example" default="all" basedir="."&gt;
      &lt;property name="project_name" value="junitSamples" /&gt;
      &lt;property name="src" location="src" /&gt;
      &lt;property name="build" location="build/classes" /&gt;
      &lt;property name="lib" location="lib" /&gt;
      &lt;property name="reports" location="reports" /&gt;
  
      &lt;target name="init" depends="clean"&gt;
          &lt;mkdir dir="${build}" /&gt;
          &lt;mkdir dir="${lib}" /&gt;
          &lt;mkdir dir="${reports}" /&gt;
          &lt;mkdir dir="${reports}/raw/" /&gt;
          &lt;mkdir dir="${reports}/html/" /&gt;
      &lt;/target&gt;
  
      &lt;target name="compile" depends="init"&gt;
          &lt;javac srcdir="${src}" destdir="${build}" description="compile the source code "&gt;
              &lt;classpath&gt;
                  &lt;fileset dir="lib"&gt;
                      &lt;include name="**/*.jar" /&gt;
                  &lt;/fileset&gt;
              &lt;/classpath&gt;
          &lt;/javac&gt;
      &lt;/target&gt;
  
      &lt;target name="clean"&gt;
          &lt;delete dir="build" /&gt;
          &lt;delete dir="${reports}" /&gt;
      &lt;/target&gt;
  
      &lt;target name="run-tests" depends="compile"&gt;
          &lt;junit printsummary="yes" haltonfailure="yes" showoutput="yes"&gt;
              &lt;classpath&gt;
                  &lt;pathelement path="${build}" /&gt;
                  &lt;fileset dir="lib"&gt;
                      &lt;include name="**/*.jar" /&gt;
                  &lt;/fileset&gt;
              &lt;/classpath&gt;
  
              &lt;batchtest fork="yes" todir="${reports}/raw/"&gt;
                  &lt;formatter type="xml" /&gt;
                  &lt;fileset dir="${src}"&gt;
                      &lt;include name="**/*Test*.java" /&gt;
                  &lt;/fileset&gt;
              &lt;/batchtest&gt;
          &lt;/junit&gt;
      &lt;/target&gt;
  
      &lt;target name="test" depends="run-tests"&gt;
          &lt;junitreport todir="${reports}"&gt;
              &lt;fileset dir="${reports}/raw/"&gt;
                  &lt;include name="TEST-*.xml" /&gt;
              &lt;/fileset&gt;
              &lt;report format="noframes" todir="${reports}\html\" /&gt;
          &lt;/junitreport&gt;
      &lt;/target&gt;
  
      &lt;target name="all" depends="clean, test" /&gt;
  &lt;/project&gt;
  </code></pre>