title: Race condition when running junit test in parallel
body: <p>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 <code>state</code> will be modified or reassigned from each test, and the doSomethingWithState() would use the variable <code>state</code> and pass it to the testing method. I know with <a href="http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#parallel" rel="nofollow">maven-surefire-plugin</a> you can run it at the method level that both a() and b() will get assigned to a thread and run it in parallel. </p>
  
  <pre><code>@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
       }
  }
  </code></pre>