JBuilder X and abstract test classes


2005-12-21 04:50:25 PM
jbuilder0
I have an abstract class that provides a lot of functionality but is
available in many "flavours" provided by subclasses.
abstract class Super {
abstract void initialise();
void foo1();
void foo2();
}
class ChildA extends Super {
void initialise() {...some code here...}
}
class ChildB extends Super {
void initialise() {...some code here...}
}
....
class ChildZ extends Super {
void initialise() {...some code here...}
}
Now I'm creating my test cases as follows;
abstract class SuperTest {
Super testInstance;
abstract void createChild();
protected void setUp() throws Exception {
super.setUp();
testInstance = createChild();
}
public void testFoo1() {
assert(expectedResult, testInstance.foo1());
}
public void testFoo2() {
assert(expectedResult, testInstance.foo2());
}
}
class ChildATest extends SuperTest {
void createChild() {
return new ChildA();
}
}
class ChildB extends Super {
void createChild() {
return new ChildB();
}
}
....
class ChildZ extends Super {
void createChild() {
return new ChildZ();
}
}
This seems to be common-sense and I've read articles saying that
"super-test-classes" and inhertitence of tests is a "good thing".
But I can get JBuilder to work with it. JBuilder fails because it
attempts to create and run the SuperTest class which is of course
abstract.
The work around is to not have SuperTest abstract and have specific
tests in each of the sub-classes, but this is just messy and duplicates
a lot of code.
Anyone got a fix for this?