Using Junit 4.12. JUnit's Before annotation is documented, but it seems to me that it is no longer needed. Apparently JUnit creates a new instance for every test, as shown in the following snippet:
import org.junit.Test;
public class BeforeTest {
TestObject testObject = new TestObject();
@Test
public void one(){
System.out.println(testObject.status);
testObject.setStatus("Used by one()");
}
@Test
public void two(){
System.out.println(testObject.status);
testObject.setStatus("Used by two()");
}
private class TestObject{
public String status;
public TestObject(){
status = "new";
}
void setStatus(String newStatus){status = newStatus;}
}
}
-----------------------------
new
new
Do we still need @Before?