![](/img/trans.png)
[英]How to verify invocations of the same mock method with the same argument that changes state between invocations in mockito?
[英]How to mock and verify method with argument T
我有一個方法:
public V doSomething(T t, Class<V> classV){}
我該如何使用模擬對象調用此方法並進行驗證?
我正在嘗試這樣:
when(mockObject.doSomething(any(MyConcreteT.class), AnotherConcrete.class).
thenReturn(obj);
verify(mockObject).doSomething(any(MyConcreteT.class), AnotherConcrete.class);
但收到一個錯誤
InvalidUseOfMatchersException:參數匹配器的無效使用!
感謝任何幫助
AFAIK,Mockito要求所有參數都是非匹配項,或者所有參數都是匹配項。 不允許混合它們。 (不過,詳細的錯誤消息應該告訴您這一點。)
嘗試:
when(mySpy.doSomething(any(MyConcreteT.class), eq(AnotherConcrete.class)).
thenReturn(obj);
verify(mySpy).doSomething(any(MyConcreteT.class), eq(AnotherConcrete.class));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.