When i run the below code, both test cases come true:
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
public class MyTest{
private int count;
@Before
public void before(){
count=1;
}
@Test
public void test1(){
count++;
assertEquals(2, count);
}
@Test
public void test2(){
count++;
assertEquals(2, count);
}
}
EXPECTED BEHAVIOUR
ACTUAL BEHAVIOUR
Why junit is reinitializing class/variable
with each test method invocation.
It is a bug in junit or is provided intentionally.
It is because of test isolation.
No test should depend on another.