Interview Questions

How Do You Use Ant to Create HTML Test Reports?

JUnit Questions and Answers


(Continued from previous question...)

How Do You Use Ant to Create HTML Test Reports?

1. Ensure that Ant's optional.jar file is either in your CLASSPATH or exists in your $ANT_HOME/lib directory.

2. Add an ANT property for the directory containing the HTML reports:

      <perty name="test.reports" value="./reports" />

3. Define the Ant task for running JUnit and generating reports:

<target name="test-html">
  <junit fork="yes" printsummary="no" haltonfailure="no">
    <batchtest fork="yes" todir="${test.reports}" >
      <fileset dir="${classes}">
        <include name="**/*Test.class" />
      </fileset>
    </batchtest>
    <formatter type="xml" />
    <classpath refid="test.classpath" />
  </junit>

  <junitreport todir="${test.reports}">
    <fileset dir="${test.reports}">
      <include name="TEST-*.xml" />
    </fileset>
    <report todir="${test.reports}" />
  </junitreport>
</target>

4. Run the test:

      ant test-html

(Continued on next question...)

Other Interview Questions