2013-02-15 142 views

回答

305

使用適當的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"); 
+15

你也可以使用'Mockito.times(...)'而非'VerificationModeFactory.times (...)'靜態導入 – 2015-11-24 10:16:09

+18

'import static org.mockito.Mockito.times;'。一般情況下,導入其中包含「內部」的包('import static org.mockito.internal.verification.VerificationModeFactory.times;')是不鼓勵的。 – Roger 2016-05-31 20:52:34

+0

有沒有寫時間(1)的另一種方式? – 2017-08-10 10:57:00

相關問題