如何使用 mockito verify() 验证一个方法被调用两次 [英] How to verify a method is called two times with mockito verify()
本文介绍了如何使用 mockito verify() 验证一个方法被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过 mockito 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");
这篇关于如何使用 mockito verify() 验证一个方法被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文