如何解决junit中可能缺少的thenreturn()异常

vd8tlhqk  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(452)

有人可以帮助做什么来解决以下提到的异常时,存根下面提到的行

Mockito.doNothing().when(customerRepository.save(customerProduct))

建议我在这里正确执行

E.g. thenReturn() may be missing.

正确的短截线示例:

when(mock.isOk()).thenReturn(true);
    when(mock.isOk()).thenThrow(exception);
    doThrow(exception).when(mock).someVoidMethod();

提示:

1. missing thenReturn()
 2. you are trying to stub a final method, which is not supported
 3. you are stubbing the behaviour of another mock inside before 'thenReturn' instruction is completed
sq1bmfud

sq1bmfud1#

Mockito医生说 doNothing() 方法的用法如下:

doNothing().when(mock).method()

因此,在您的情况下,您可能需要尝试以下方法:

Mockito.doNothing().when(customerRepository)
    .save(customerProduct)

相关问题