2012-07-23 125 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,它提供了最终的类/方法嘲讽。

希望可以帮到