【发布时间】:2021-09-08 13:54:32
【问题描述】:
我正在尝试为各种结果模拟一个函数。首先,我嘲笑它抛出异常如下:
Mockito.when(ClassName.methodName(Matchers.any(), Matchers.any())).thenThrow(new ExceptionName());
现在,我想模拟一个返回一些输出的案例。所以,我尝试如下:
Mockito.when(ClassName.methodName(Matchers.any(), Matchers.any())).thenReturn(output);
但它正在抛出异常(可能是因为我已经模拟它抛出异常)
我应该如何解开它,以便我可以使用它来提供正确的输出?
【问题讨论】:
标签: unit-testing exception junit mockito spring-boot-test