I am wondering would it have some race condition if I run my tests in parallel and the two tests (below) share an instance variable? So my test class runs with SpringJunit4ClassRunner, and I have 2 tests method a() and b(), the variable state
will be modified or reassigned from each test, and the doSomethingWithState() would use the variable state
and pass it to the testing method. I know with maven-surefire-plugin you can run it at the method level that both a() and b() will get assigned to a thread and run it in parallel.
@RunWith(SpringJUnit4ClassRunner.class)
public class TestA {
private Object state;
@Test
public void a() {
stateObjectA();
doSomethingWithState();
assertion();
}
@Test
public void b() {
stateObjectB();
doSomethingWithState();
assertion();
}
private void stateObjectA() {
// do some mocking and setup state
}
private void stateObjectB() {
// do some mocking and setup state
}
private void doSomethingWithState() {
// use the state object and feed into the testing method
}
}