【发布时间】:2013-10-15 12:33:09
【问题描述】:
当我运行下面的代码时,两个测试用例都实现了:
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);
}
}
预期行为
- test1 - 成功
- test2 - 失败(按预期计数将变为 3)
实际行为
- test1 - 成功
- test2 - 成功
为什么 junit 对于每个测试方法调用都是reinitializing class/variable。
这是junit中的一个错误或者是故意提供的。
【问题讨论】:
标签: java unit-testing junit junit4 junit3