180
我想驗證一個方法是否被調用兩次或多次通過mockito驗證。我使用驗證,並抱怨是這樣的:如何驗證一個方法被調用兩次與mockito驗證()
org.mockito.exceptions.verification.TooManyActualInvocations:
Wanted 1 time:
But was 2 times. Undesired invocation:
我想驗證一個方法是否被調用兩次或多次通過mockito驗證。我使用驗證,並抱怨是這樣的:如何驗證一個方法被調用兩次與mockito驗證()
org.mockito.exceptions.verification.TooManyActualInvocations:
Wanted 1 time:
But was 2 times. Undesired invocation:
使用適當的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.times(...)'而非'VerificationModeFactory.times (...)'靜態導入 – 2015-11-24 10:16:09
'import static org.mockito.Mockito.times;'。一般情況下,導入其中包含「內部」的包('import static org.mockito.internal.verification.VerificationModeFactory.times;')是不鼓勵的。 – Roger 2016-05-31 20:52:34
有沒有寫時間(1)的另一種方式? – 2017-08-10 10:57:00