简体   繁体   English

Mockito-验证存根

[英]Mockito - verifying a stub

I have a stub that is used across different test cases and I need to verify that certain methods are not called in some of these test cases. 我有一个可用于不同测试用例的存根,我需要验证在某些测试用例中未调用某些方法。

The problem I'm having with mocks I get through Mockito.mock() is that calling their methods have no effect. 我通过Mockito.mock()获得的Mockito.mock()的问题是调用它们的方法无效。

So, can I somehow mock a stub so that method calls are executed as they should and at the same time they are logged so that they can be verified? 因此,我可以以某种方式模拟存根,以便按应有的方式执行方法调用,同时记录它们以便可以对其进行验证吗?

I think what you are looking for is spies. 我认为您正在寻找间谍。 See here: http://mockito.googlecode.com/svn/branches/1.7/javadoc/org/mockito/Mockito.html (#13 in the list). 参见此处: http : //mockito.googlecode.com/svn/branches/1.7/javadoc/org/mockito/Mockito.html (列表中的第13个)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM