You can use the junitreport task to collect test results.
If you need to print totals in an assembly file, you can use a filter chain to extract information from the generated report.
Maybe (should?) Be an easier way to do this, but I haven't seen it.
<target> <junit failureProperty="test.failure"> <classpath refid="classpath.test" /> <formatter type="xml" /> <batchtest todir="tmp/results"> <fileset dir="${tst-dir}" includes="**/Test*.class" /> </batchtest> </junit> <junitreport todir="tmp"> <fileset dir="tmp/results" /> <report todir="tmp/report" /> </junitreport> <concat> <fileset file="tmp/report/overview-summary.html" /> <filterchain> <linecontainsregexp> <regexp pattern='title="Display all tests"' /> </linecontainsregexp> <tokenfilter> <replaceregex pattern='<td><a href="all-tests.html" title="Display all tests">(\d+)</a></td><td><a href="alltests-fails.html" title="Display all failures">(\d+)</a></td><td><a href="alltests-errors.html" title="Display all errors">(\d+).*$' replace="Run: \1, Failed: \2, Errors: \3" /> </tokenfilter> </filterchain> </concat> <fail message="test failed" if="test.failure" /> </target>
The output will look something like this:
Buildfile: C:\\test\unit_test.xml test: [junit] Test MyUnitTest FAILED [junit] Test MyUnitTest2 FAILED [junitreport] Processing C:\\test\tmp\TESTS-TestSuites.xml to C:\DOCUME~1\xxx\LOCALS~1\Temp\1\null1075123857 [junitreport] Loading stylesheet jar:file:/C:/eclipse/eclipse-jee-ganymede-SR2-win32/eclipse/plugins/org.apache.ant_1.7.0.v200803061910/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] Transform time: 906ms [junitreport] Deleting: C:\DOCUME~1\xxx\LOCALS~1\Temp\1\null1075123857 [concat] Run: 8, Failed: 4, Errors: 1 BUILD FAILED C:\test\unit_test.xml:32: test failed Total time: 1 second
If you are performing a large number of tests, you will now have the overhead of extracting the report generation.
source share