本文介绍了如何使用嘲笑的verify()两次调用方法来验证方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过嘲笑验证来验证方法是否至少被调用过一次.我使用了verify,它抱怨像这样:
I want to verify if a method is called at least once through mockito verify. I used verify and it complains like this:
org.mockito.exceptions.verification.TooManyActualInvocations:
Wanted 1 time:
But was 2 times. Undesired invocation:
推荐答案
使用适当的VerificationMode:
Using the appropriate VerificationMode:
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
verify(mockObject, atLeast(2)).someMethod("was called at least twice");
verify(mockObject, times(3)).someMethod("was called exactly three times");
这篇关于如何使用嘲笑的verify()两次调用方法来验证方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!