I have the following in my build.xml
:
<junit fork="yes" printsummary="yes" filtertrace="yes">
<classpath>...</classpath>
<test name="tests.AllTests"/>
<formatter type="plain" usefile="false"/>
</junit>
I would like the JUnit results to be reported for each test as soon as they complete, unfortunately the JUnit task only prints the test results after the whole test case has completed. The test case (AllTests) is rather large, so I have to wait quite a while for the output. Is there any way to make <junit>
print individual test results immediately?
I believe the built-in JUnit formatters buffer everything until the end. You should be able to write your own formatter implementation which extends
org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
so that it flushes to STDOUT immediately, but I've never done it.You can use this blog where the author makes a custom formatter and shows both the code and how to use it in the build.xml http://shaman-sir.wikidot.com/one-liner-output-formatter
There is also a similar SO question with similar info How do I configure JUnit Ant task to only produce output on failures?
I followed dkatzel's suggestion to write my own
JUnitResultFormatter
. Here is the code for my JUnitFormatter:And this is how I use it in the Ant script:
Note that the class must be compiled with
ant.jar
andant-junit.jar
on the classpath.