From: Robert Rudolph <rrr@gm...> - 2002-10-14 19:02:34
The framework defines a mechanism to enhance test processing by the interface TestListener.
However, it is difficult to register a custom TestListener in a way it is present in all tests of a TestRunner.
The standard TestRunner implementations have no extension mechanism to register additional
If the property
is present, interpret the value of this property as a comma-separated list of fully qualified
classnames. In the initialization code of the TestRunner, instantiate each of these classes,
cast them to TestListener and register them as listeners on the TestResult created by the
TestRunner. I suggest to put the implementation in BaseTestRunner, because the code to
process properties is located there. A new method registerDefaultTestListeners() could do
the job. Every TestRunner implementation should call that method after creating its
To ease the use of TestListener implementations for JUnit enhancements, I suggest a method
named finish() or similar in TestListener to signal that the last test was run. The TestListener
implementation should generate summaries and free ressources in that method.
Why? - A scenario:
On a performance-oriented refactoring, I want to compare the performance of different
functionally equivalent method implementations by JUnit tests. The typical test method
calls the "old" implementation, then the "new" implementation and compares. This
ist "standard JUnit". To measure the performance, I take the execution time of the "old"
and "new" implementation. My base class RefactoringTestCase has methods like
startOldImplementation(), endOldImplementation(), startNewImplementation(),
endNewImplementation() which are called within each test, and methods
getOldImplementationTime(), getNewImplementationTime() to retrieve the
net execution time of the old and new implementation. My RefactorTestListener
collects the timings in the endTest() method, if the test is a RefactoringTestCase,
and appends the result to a textfile.
I use different TestRunner-s: the one in Ant, the textui version directly in the IDE
and occasionnally the GUI-version standalone. It would help not to patch these
TestRunners on every new release.
Get latest updates about Open Source Projects, Conferences and News.