« You know you want it: Wiki SVG whiteboard | Main | Sam Ruby: Inter-net »

Ant's junit task is too verbose

I've been playing with other peoples code. Which involves running other people's unit tests via ant/maven. Which are very very chatty.

Now, I don't use the junit task in Ant for precisely this reason, but I'd forgotten just how chatty the task is. Here's a dump from something I've started working on yesterday:

  test:
................... Time: 4.025
OK (19 tests)

Here's an amended dump from picocontainer - there's nothing special about picocontainer I just happen to have a bash shell open for it:

test:test:
 [junit] Running org.picocontainer.defaults.ComponentSpecification...
 [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.07 sec
 [junit] Running org.picocontainer.defaults.DefaultComponent...
 [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.06 sec
 [junit] Running org.picocontainer.defaults.DefaultPico...
 [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.21 sec
 [junit] Running org.picocontainer.defaults.Default...
 [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.07 sec
 [junit] Running org.picocontainer.defaults.DefaultPico...
 [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.071 sec
 [junit] Running org.picocontainer.defaults.DefaultPicoContainer...
 [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.06 sec
 [junit] Running org.picocontainer.defaults.DefaultPicoContainer...
 [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.15 sec
 [junit] Running org.picocontainer.defaults.DefaultPicoContainer....
 [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.06 sec
 [junit] Running org.picocontainer.defaults.DefaultPicoContainer....
 [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.151 sec
 [junit] Running org.picocontainer.defaults.DefaultPicoContainerWith...
 [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.06 sec
 [junit] Running org.picocontainer.defaults.DummiesTestCase
 [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.04 sec
 [junit] Running org.picocontainer.defaults.OldDefault...
 [junit] Tests run: 29, Failures: 0, Errors: 0, Time elapsed: 0.251 sec
 [junit] Running org.picocontainer.defaults.ParameterTestCase
 [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.071 sec
 [junit] Running org.picocontainer.extras.CompositePico...
 [junit] Tests run: 11, Failures: 0, Errors: 0, Time elapsed: 0.08 sec
 [junit] Running org.picocontainer.extras.DefaultLifecycle...
 [junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.34 sec
 [junit] Running org.picocontainer.extras.HierarchicalComponent...
 [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.07 sec
 [junit] Running org.picocontainer.extras.ImplementationHiding...
 [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.08 sec
 [junit] Running org.picocontainer.NoPicoTestCase
 [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.04 sec
 [junit] Running org.picocontainer.PicoInvocation...
 [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.05 sec
 [junit] Running org.picocontainer.PicoPicoTestCase
 [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.07 sec

Does anyone finds this verbiage in any way useful?

Maybe's there's way to turn this off, I haven't found it. But what I don't understand is why the task by default replaces JUnit's nicely minimal output with it's own fluff. To me, it looks suspiciously like a malformed report *. True that picocontainer has about 100 tests and I have only 19, but my output won't get any longer, whereas picocontainer's will keep growing with every new test case.

I wrote some code years ago that walks a src/ directory and loads any class that has a marker interface into a suite and executes it. This was so I wouldn't have to keep manually adding test class to a suite and to avoid the way master suites force you into bidirectional dependencies for projects with subprojects. Classic programmer laziness. Its jar file is one of 3/4 core dependencies (excluding Ant) I have for all projects - the others are junit and jdepend, and sometimes catalina-ant.

One side effect of this code is that it makes for a simple Ant task:


<target name="test" depends="compile-test"
description="run the junit tests">
<echo />
<java
fork="${test.fork}"
classname="${test.classname}"
taskname="${test.task.name}"
failonerror="${test.failonerror}"
classpathref="test.classpath" >
<arg value="${test.alltests}" />
<sysproperty key="install.location"
value="${install.target}"/>
</java>
</target>

Maybe I could change the marker to a *Test* pattern or an aspect, but it's so simple to create a test class template with the marker for any IDE it doesn't seem worth it. The downside is that you end up loading classes twice, which is not too slow, but slower than loading them once. [Btw, if you spotted the 4 second run for 19 tests above, don't worry too much - the tests are testing the lifecycle logic of a timer/scanner and are littered with sleep() calls]

I have thought about hacking something this straight into JUnit and now that I've seen the way Erich Gamma responded to Scott Sterling's exellent JUnit classloader fix, maybe I should. Aside from any inefficiencies, having to manually manage suites and testcases is not good from a usability standpoint (yes I know some IDEs will take care of this, that's not the point, plus I'm not much on depending on IDEs for build management).

* As for the gui or reporting output, a mockup of my ideal display is [here]


August 15, 2003 03:37 PM

Comments

Chuck Hinson
(August 15, 2003 07:32 PM #)

You just haven't looked hard enough (or recently enough)

junit haltonerror="true" haltonfailure="true" printsummary="no"

is what I use.

It produces no output if the tests pass or one line of output if the test fails (the name of the test that failed). Seems like that meets your requirements

Edwin Hautus
(August 28, 2003 10:15 AM #)

I also have problems understanding the logic behind the ANT JUnit task.

In my case, I have collected all the tests in a TestAll suite. The advantage of a suite over ANT patterns is that I can run the suite using the IDEA JUnit integration and be sure to be running the same tests as in the nightly build.

Unfortunately, the ANT JUnit task will only tell me that the suite as a whole has failed, not which particular test (or assertion). :-(

Trackback Pings

TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1064