junit verify用法 - 如何驗證一個方法被mockito verify()調用兩次




1 Answers

當然,使用適當的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教學 mockito中文

我想驗證一個方法是否通過mockito驗證被調用兩次或多次。 我用驗證,它抱怨這樣:

org.mockito.exceptions.verification.TooManyActualInvocations: 
Wanted 1 time:
But was 2 times. Undesired invocation:



Related