Java 如何解决junit中可能缺少的thenReturn()异常
有人能帮助解决下面提到的异常吗 当短截线位于上述线下方时Java 如何解决junit中可能缺少的thenReturn()异常,java,spring,junit,mockito,Java,Spring,Junit,Mockito,有人能帮助解决下面提到的异常吗 当短截线位于上述线下方时 Mockito.doNothing().when(customerRepository.save(customerProduct)) 建议我在这里正确执行 E.g. thenReturn() may be missing. 正确的短截线示例: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(
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
telldoNothing()
方法应如下使用:
doNothing().when(mock.method())
因此,在您的情况下,您可能需要尝试以下方法:
Mockito.doNothing().when(customerRepository)
.save(customerProduct)
它不应该是Mockito.doNothing().when(customerRepository).save(customerProduct)
?