我对期望和验证的目的和差异感到困惑。例如。
@Tested FooServiceImpl fooService;
@Injectable FooDao fooDao;
@Test
public void callsFooDaoDelete() throws Exception {
new Expectations() {{
fooDao.delete(withEqual(1L)); times = 1;
}};
fooService.delete(1L);
new Verifications() {{
Long id;
fooDao.delete(id = withCapture()); times = 1;
Assert.assertEquals(1L, id);
}};
}
首先,如果这个测试编写得不好,请告诉我。
第二,我的问题:期望部分对我来说似乎是多余的,我无法想出一个不会出现的例子。