Java Reference
In-Depth Information
XML D instead of plain text. The junitreport transforms the XML test results into an
HTML report using XSL . We change the junit task to create an XML report file in the
${target.report.dir} directory E and then create a new report target that generates
the HTML report F .
We begin the report target by creating the directory where the HTML report will
be generated G . We call the junitreport task to create the report H . The task scans
the XML test results specified as an Ant fileset I and generates the HTML report to
our specified location J .
The next step is learning how to batch tests. 7
The future of JUnit reports
The Ant junit task produces XML output containing detailed results of the exe-
cution of JUnit tests. This task isn't the only tool to produce XML documents of
this format; so does Maven's Surefire plug-in. Several tools also consume this
format in addition to junitreport, like maven-surefire-reports , and different
CI servers.
As of Ant 1.7.1, the generated HTML reports don't list skipped tests because Ant
doesn't use JUnit 4 features. Note that in the previous version of JUnit there was
no special status for skipped tests. We should expect the XML schema for JUnit
reports to evolve, a topic currently under discussion on the Apache Ant 7 wiki.
9.8
Batching tests
Our current build file calls the junit task through the test target to invoke specific
test cases. Although this is fine for a small set of test classes, it may become unwieldy
for larger sets of classes. One way to remedy this situation is to group tests together in
a test suite and invoke the test suite from Ant.
Alternatively, you can direct Ant to batch tests together by using wildcards to find
tests by class names. The batchtest element uses a fileset with wildcards to find test
classes, as shown in listing 9.7 (with changes from listing 9.4 in bold).
Listing 9.7
Using batchtest to find test cases
<project name="example" default="test">
[...]
<target name="test" depends="compile">
<mkdir dir="${target.report.dir}"/>
<property name="tests" value="Test*"/>
<junit printsummary="yes" haltonerror="yes" haltonfailure="yes"
fork="yes">
<formatter type="plain" usefile="false"/>
<formatter type="xml"/>
B
7
http://wiki.apache.org/ant/Proposals/EnhancedTestReports
 
 
 
 
 
Search WWH ::




Custom Search