2012-07-23 108 views

回答

3

你檢查MissingMethodInvocationException異常消息?

它說:

when() requires an argument which has to be 'a method call on a mock'. 
For example: 
    when(mock.getArticles()).thenReturn(articles); 

Also, this error might show up because: 
1. you stub either of: final/private/equals()/hashCode() methods. 
    Those methods *cannot* be stubbed/verified. 
2. inside when() you don't call method on mock but on some other object. 
3. the parent of the mocked class is not public. 
    It is a limitation of the mock engine. 

要麼類Level是最後的(顯然不是,因爲我記得擴展此類)或getSyslogEquivalent是最後的(最好的猜測)。

所以你應該修改你的設計或測試設計,或者試試Powermock,它提供了最終的類/方法嘲諷。

希望可以幫到