【发布时间】:2012-11-02 17:19:57
【问题描述】:
我不太了解以下测试的行为。仔细看,test_OK 和 test_Not_OK 是完全等价的——唯一的区别是 test_OK 具有“内联”callMethod。
但是,test_OK 通过,而 test_Not_OK 失败。这种行为有原因吗?
public class MethodCallTest {
@Test
public void test_Not_OK() {
new NonStrictExpectations() {
Whatever w;
{
callMethod();
}
private void callMethod() {
w.method();
result = 1;
}
};
assertEquals(new Whatever().method(), 1); //fails
}
@Test
public void test_OK() {
new NonStrictExpectations() {
Whatever w;
{
w.method();
result = 1;
}
};
assertEquals(new Whatever().method(), 1); //passes
}
public static class Whatever {
public int method() {
return 0;
}
}
}
【问题讨论】:
标签: java jmockit expectations