From: Paul_Holser@Landsafe.Com - 2002-03-27 00:18:03
|
the only gotcha i can think of is that by having TestSuite(Class) ctor perform a check for a suite() method, a test class implementor had better not provide a suite() method like this: public class MyTest extends TestCase { public static Test suite() { return new TestSuite( MyTest.class ); } } as you'll end up in an unbroken recursion. and that would be a bad gotcha. now granted, a test class writer usually wouldn't provide a redundant suite() like that, she'd just let the TestRunner construct the suite reflectively. but, she might do this: public class MyTest extends TestCase { public static Test suite() { return new MyTestSetup( new TestSuite( MyTest.class ) ); } } so maybe it's better to leave things the way they are, and if you need a suite from another class, like in an AllTests, do this: public class AllTests extends TestCase { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest( MyTest.suite() ); suite.addTest( HerTest.suite() ); return suite; } } instead of: public class AllTests extends TestCase { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite( MyTest.class ); suite.addTestSuite( HerTest.class ); return suite; } } and if the desired component of the composite doesn't have a suite() method, use the addTestSuite(Class) method. thanks for the discussion. cheers, p Paul Holser 03/25/2002 01:05 PM To: jun...@li... cc: Subject: reflective suite building--TestRunner vs. TestSuite hi all... i noticed that when a TestRunner's main() is given the name of a test class, to get a test suite the TestRunner does a getTest(testClassName), which first reflects on the named class for a suite() method, invoking it if present, else constructing a TestSuite using the TestSuite constructor that accepts a Class object. pretty handy. i was wondering why the constructor TestSuite(Class) doesn't do the reflective search for a suite() on the target class itself. that way when composing suites you could say: suite.addTestSuite( SomeClass.class ); suite.addTestSuite( SomeOtherClass.class ); rather than: suite.addTest( SomeClass.suite() ); suite.addTest( SomeOtherClass.suite() ); are there particular motivations for having TestRunners build suites by looking for a suite() method on the target class first, while having the TestSuite constructor not do this check? curious, p |