You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Stefan Bodewig <bo...@bost.de> on 2000/07/20 12:50:13 UTC

The JUnit task

The task I've just commited is Thomas' version with some minor and one
rather big change. The latter will probably break Thomas' own system
but we should find another solution for that.

Thomas had a logic in place that wouldn't run a testcase if Ant knew
this one had succeeded sometime earlier. It detected this by searching
for a file TEST-classname.xml - if it was present, the test was
skipped. Such a file would be generated each time a test was run
successfully.

The only way you could ensure all your tests would run was to remove
the TEST-* files manually. At least I cannot find a simple logic to
ensure that the TEST- file was actually newer than the class file of
the testcase and all class files of all units the test relied on.

I've commented out the parts responsible for this completely (search
for "removed --SB" in JUnitTask) - so Ant will run all tests specified
without thinking about prior results.

The typical syntax is

<junit>
  <test name="classname" />
</junit>

There are a couple of attributes to junit as well as to test.

junit:

* defaulthaltonerror, defaulthaltonfailure you can stop the tests and
the build process on errors or unittest failures. Both can be
overridden on a test by test basis.

* defaultprintsummary Print something like 
Tests run: 16, Failures: 0, Errors: 0, Time elapsed: 0,067 sec
after each test. Can be overridden on a test by test basis.

* defaultprintxml Print an XML file with detailed information about
the test results. See below. Can be overridden on a test by test basis.

* defaultoutfile. A boolean that will set the output of all tests to
TEST-classname.xml if not overridden by the test's outfile
attribute. See below.

* fork - like in <java>. Actually it doesn't work too well without fork
- this will be improved by using Conor's classloader. Can be set on a
test by test basis.

* junit - CLASSPATH part for JUnit. Works together with the nested
classpath attribute. Has no meaning if fork is off.

* timeout - same as the attribute to the new exec task.

* jvmargs - whatever you need to provide as additional arguments:
-Djava.compiler=NONE -Xmx1024m or so.

test:

* name - classname of the unittest.

lot's of attributes that override the defaults set on the junit
element.

I'd like to restructure this a little. XMLJUnitResultFormatter is the
class responsible for writing the XML output. This one implements the
interface JUnitResultFormatter. The actual TestRunner can handle
arbitrary implementations of this interface. 

So instead of the printxml and outfile attributes I'd like to have a
nested

<formatter classname="..." out="..." />

element. This would give a much larger flexibility to the user - write
your own formatter for test results - and don't bother Ant's core with
it. We could keep the XML version (as is or modified) as a simple
supplied version, maybe together with a plain text one.

Feedback is welcome and I'll wait for comments before I proceed.

Stefan