Bug 47913 - Allow to add one or more Junit RunListener instances in the Junit task
Allow to add one or more Junit RunListener instances in the Junit task
Product: Ant
Classification: Unclassified
Component: Optional Tasks
All All
: P2 enhancement (vote)
: ---
Assigned To: Ant Notifications List
Depends on:
  Show dependency tree
Reported: 2009-09-28 14:31 UTC by olivier dupuy
Modified: 2009-10-21 13:56 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description olivier dupuy 2009-09-28 14:31:58 UTC

Not fond in the existing bugs or RFE.

I try to solve the following problem. We have some hundreds of unit tests running. It happens that one of them takes a lot of time to run or is blocked. In an IDE like Eclipse, I can see which test is running in the Junit window.
When I run the tests through the Junit task of Ant, I cannot. I have to wait for the test report.

Junit provides a way to add one or more RunListener instances (http://junit.sourceforge.net/javadoc_40/org/junit/runner/notification/RunListener.html) to a JunitCore object. The Junit RunNotifier class allows also to add some notifiers.
The problem is that I do not have any hook to do this at all while the runner used by Ant has normally access to these classes. I even suppose that it already takes advantage of them.

What I suggest is to add to the Junit task an optional attribute, which would be a comma delimited list of listener FQN (or if you prefer a single one a one could call others).
<junit runlistener="com.acme.MyListener">

With this I am free to do anything that I want, report a progress in one or many log files, timing my tests, detect a problem and link it to a precise test...


Comment 1 olivier dupuy 2009-09-28 14:34:19 UTC
...and with the FQN avaialble, the Junit runner can create an instance of it and add it after the other listeners. It should to the trick.

Comment 2 J.M. (Martijn) Kruithof 2009-10-01 12:05:16 UTC
Could you please elaborate what is not feasible using the current options,
most notably the formatter element?
Comment 3 olivier dupuy 2009-10-08 09:50:48 UTC

I still want the output to be sent to the XML formatter as now.
I just want some additional behavior. I suppose that the plain formatter could give some details but I do not want to run the unit tests twice, it takes already long enough.

I just want some information during the tests that I can log where I want. Multiple RunListeners can be used. I guess that you already use one of them for your formatter. I just to want the option to add mine to the one of the formatter.

The other option I now think of is to extend/decorate the XML formatter. This could be fine but if I need to change to a different formatter for any reason, I need to redo my work. The listener solution would be more flexible I think.  


Comment 4 Stefan Bodewig 2009-10-09 01:07:59 UTC
Olivier, do you realize that you can add more than one formatter element to the junit task and thus can add more than one formatter during a single test run?

And then formatter supports a classname attribute that you can use to attach any class that implements the JUnitResultFormatter interface (an extension of junit-framework.TestListener) to the running tests.
Comment 5 Stefan Bodewig 2009-10-21 11:54:36 UTC
It really seems as if all the functionality you are asking for is already there (use multiple formatters).  What is missing?
Comment 6 olivier dupuy 2009-10-21 13:56:13 UTC
Hi Stefan,

I have just tested according to your suggestion, creating a class extending BriefJUnitResultFormatter and decorating it to log the test being started or other then putting it in a jar file added to the classpath.
It works perfectly, I can now see the progress of the tests.

Thanks a lot, I had not realized from the documentation that multiple formatters could be used.
I close the request