简体   繁体   English

Mockito - 验证对象根本没有被调用

[英]Mockito - verify object not invoked at all

How can you verify a mocked object is not invoked at all? 如何验证未调用模拟对象? I am trying to test the empty implementation of an interface method using Mockito. 我试图使用Mockito测试接口方法的空实现。

I use org.mockito.Mockito.verifyNoMoreInteractions . 我使用org.mockito.Mockito.verifyNoMoreInteractions

In fact, personally, I always include this section in all my Mockito tests: 事实上,就个人而言,我总是在我的所有Mockito测试中都包含这一部分:

@After
public void after() {
    verifyNoMoreInteractions(<your mock1>, <your mock2>...);
}

So it acts as a handy catch-all to ensure that the test has no left-over, unexpected invocations that I haven't specifically verified. 因此,它可以作为一个方便的捕获所有,以确保测试没有遗留的,我没有特别验证的意外调用。 I find that more useful than cluttering the tests with specific verifyZeroInteractions . 我发现这比使用特定的verifyZeroInteractions混乱测试更有用。

请参阅Mockito API第7条。确保在模拟上从未发生过互动

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

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