简体   繁体   English

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

[英]How can I resolve thenReturn() may be missing exception in junit

Can someone please help what to do to resolve below mentioned exception When stubbing below mentioned line有人可以帮忙解决下面提到的异常当存根下面提到的行时

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

Suggest me correct execution here建议我在这里正确执行

E.g. thenReturn() may be missing.

Examples of correct stubbing:正确的存根示例:

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

Hints:提示:

 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

The mockito docs tell doNothing() method should be used like this: mockito 文档告诉doNothing()方法应该像这样使用:

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

So in your case you may want to try this:所以在你的情况下,你可能想试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM