일반적으로 Expectations
은 differnt 반환 값으로 값을 모의하는 데 사용된다는 것을 알고 있습니다. 예를 들면 다음과 같습니다.결과가없는 Expectations 블록과 Verifications 블록이 동일한 것입니까?
new Expectations() {{
bar.getGreeting();
result = "Hello, world!";
times = 2;
}};
나는 result
이 선택 사항임을 알아 챘습니다. 이 시점에서이 블록은 메서드가 두 번 호출되었다는 것을 확인하고 그렇지 않으면 MissingInvocation
오류를 발생시킵니다. 그래서 예를 들면 :
@Test
public void testRunFoo(@Mocked final Bar bar) {
Foo foo = new Foo(bar);
foo.runFooWithBarTwice(); //Successful
//foo.runFooWithoutBar(); //Will throw a MissingInvocationException
new Verifications() {{
bar.runBar();
times = 2;
}};
}
가 Expectations
블록 결과없이 같은 일을 Verifications
블록으로 :
@Test
public void testRunFoo(@Mocked final Bar bar) {
Foo foo = new Foo(bar);
new Expectations() {{
bar.runBar();
times = 2;
}};
foo.runFooWithBarTwice(); //Successful
//foo.runFooWithoutBar(); //Will throw a MissingInvocationException
}
내가 대신 Verifications
을 사용하는 것으로이 코드는 같은 일 것으로 보인다 것으로 나타났습니다? 당신은 당신의 개인 취향에 따라 어느 쪽을 사용할 수 있습니까? 아니면 두 사람 사이에 미묘한 차이가 있습니까?