I am writing a test class for an implementation of an interface, and want to test my implementation against another implementation (i.e. to ensure consistency). The test methods will then test each of the interface methods to check this.
To do this I could:
a) create a private static
constant fields of the original implementation and my new implementation:
public class MyImplTest extends TestCase {
private static OldImpl _original;
private static MyImpl _myImpl;
static {
// instantiate _original and _myImpl
}
// My tests
}
b) create private
fields of the two implementations, and instantiate them using setUp()
:
public class MyImplTest extends TestCase {
private OldImpl _original;
private MyImpl _myImpl;
public void setUp(){
// instantiate _original and _myImpl
}
// My tests
}
Is either of these preferred / considered good style? My instinct suggests (b), but I want to create quite large objects, and setUp()
gets run for each testSomething()
method in the TestCase
, so both _original
and _myImpl
would be created multiple times.
FWIW, I'm using JUnit 3.