简体   繁体   中英

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.

I use org.mockito.Mockito.verifyNoMoreInteractions .

In fact, personally, I always include this section in all my Mockito tests:

@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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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