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;
}
}
}