title: How can I make JUnit let me set variables in one test case and access them in other if they are in the same class
body: <p>Let say I have a test class called MyTest.</p>
  
  <p>In it I have three tests.</p>
  
  <pre><code>public class MyTest {
  
  AnObject object;
  
  @Before
  public void setup(){
    object = new AnObject();
    object.setSomeValue(aValue);
  }
  
  @Test
  public void testMyFirstMethod(){
      object.setAnotherValue(anotherValue);
      // do some assertion to test that the functionality works
      assertSomething(sometest);
  }
  
  @Test
  public void testMySecondMethod(){
      AValue val = object.getAnotherValue();
      object.doSomethingElse(val);
      // do some assertion to test that the functionality works
      assertSomething(sometest);
  }
  </code></pre>
  
  <p>Is there any way I can use the value of <code>anotherValue</code>, which is set with its setter in the first test, in the second test. I am using this for testing database functionality. When I create an object in the DB I want to get its GUID so I can use this to do updates and deletes in later test methods, without having to hardcode the GUID and therefore making it irrelevant for future use.</p>