2
我不太瞭解以下測試的行爲。看看它,和test_Not_OK
是嚴格等價的 - 唯一的區別是有「內聯」callMethod
。使用實例初始化程序調用的方法記錄期望
但是,通過,而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;
}
}
}