Niklas Mehner - 2003-06-10

Logged In: YES
user_id=52085

What do you think about doing this the other way round:
suite() still returns a CoverageDecorator, but
CoverageDecorator uses the Suite returned by coveredSuite(),
if available:

public class SomeTest extends TestSuite {

public Test suite() {
return new CoverageDecorator(SomeTest.class, ...);
}

public Test coveringSuite() {
TestSuite result = new TestSuite();
result.addTest(...);
...

return result;
}
}

This way a coverage test is always performed for this class.
Requiring the user to use
junit.textui.TestRunner.run(testClass.coverageSuite());
to start the coverage test is imho not a very good idea,
because with many test runners (for example ant) you just
specify the names of the tests to be run ("run *Test.java").

I think in that case the only place that needs to be changed is
CoverageDecorator.createInstrumentedTest() (line 88):

[pseudocode]

Class clazz = cl.loadClass(testClass.getName());

if (clazz.hasMethod("coverageSuite")) {
return invokeMethod("coverageSuite");
}

return new TestSuite(clazz,
clazz.getName() + appendToName);

Is this approach ok with you?