我不太了解下面测试的行为。看着它,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;
}
}
}