org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'


異常原因:

1.mockito的jar包中缺少方法

2.mock方法的時候,返回的是對象,而對象沒有重寫equals方法

3.mock的實例方法調用方法錯誤

解決方法:

1.用powermock中的api解決問題,在類中添加:@RunWith(PowerMockRunner.class)

2.如果是第二種情況,則需要重寫返回對象的equals方法

3.

A a = new A();

PowerMockito.when(a.getTemplate()).thenReturn(template);

改成:

@Mock
private A a= spy(new A());

PowerMockito.when(a.getTemplate()).thenReturn(template);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM