Thursday, 8 August 2013

Running a Test Suite of the same class but with different initial conditions

Running a Test Suite of the same class but with different initial conditions

In JUnit 4, I am looking to write a test suite that is made up of multiple
flavors of the same test case, just with different initial conditions on
each one. Here is an example:
import java.io.File;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({MultiInputClientServerIntegrationTest.NormalInput.class,
MultiInputClientServerIntegrationTest.SimulationHashIssue.class})
public class MultiInputClientServerIntegrationTest {
@RunWith(Suite.class)
@SuiteClasses({TestClientServerIntegration.class})
public class NormalInput {}
@RunWith(Suite.class)
@SuiteClasses({TestClientServerIntegration.class})
public class SimulationHashIssue {
public imulationHashIssue() {
TestClientServerIntegration.simulation = new
File("test\\BEECHA01\\sim2.zip");
TestClientServerIntegration.inputFile = "files\\config.in";
}
}
}
As you can see, both inner classes have SuiteClasses of the
TestClientServerIntegration.class but the second one is changing some
static variable values. I am finding that this constructor never gets
called, so these statics never get changed.
My end goal is to run this TestClientServerIntegration.class over and over
with multiple types of input. If I can run a test suite this way, that
would be ideal -- so hopefully it is possible. I'd like to do as little
hacking of JUnit as possible, but what needs to get done will get done.

No comments:

Post a Comment