【发布时间】:2015-07-25 11:44:59
【问题描述】:
我对期望和验证的目的和区别感到困惑。例如
@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);
}};
}
首先,如果这个测试写得不好/经过深思熟虑,请告诉我。
第二,我的问题:期望部分对我来说似乎是多余的,我想不出一个没有的例子。
【问题讨论】:
-
我更改了标题,以便在页面底部更好地反映您的问题。如果我误解了问题,请随时恢复我的更改。
-
旧线程,我知道,但我的理解是松散而简洁的:
Expectations块处理可能发生的事情;Verifications块处理必须发生的事情。
标签: java unit-testing testing junit jmockit