【发布时间】:2021-04-15 18:39:01
【问题描述】:
我有这段简单的代码,但看不懂它的逻辑和含义。
void findByIdThrows(){
given(addressRepository.findById(1)).willThrow(new RuntimeException("boom iii"));
assertThrows(RuntimeException.class, () -> servic.findById(1));
then(addressRepository).should().findById(1);
}
这是否意味着:如果您在查找 id #1 的地址期间遇到 RuntimeException,那么断言我将给出 RuntimeException?
最后一行(然后....)究竟做了什么?
【问题讨论】:
-
我建议阅读
bdd-mockito上的教程,例如this one on Baeldung. -
我看到了链接。这是一个有用的参考。感谢分享。
标签: java spring spring-boot testing junit