Mockito: verify a method was not called (never, verifyNoInteractions)
Codemia Knowledge Hub ·
To verify that a specific method was not called using Mockito, use verify(mock, never()).methodName(args). never() is the most direct and readable way to assert non-invocation. Mockito also has verifyNoInteractions(), which asserts a mock had zero interactions of any kind, and verifyNoMoreInteractions(), which asserts no unverified interactions remain. Each expresses a different testing intent.
verify with never(): one specific method was not called
never() is the standard way to verify that one particular method was not invoked:
never() is equivalent to times(0) but reads more naturally:
Prefer never(): "this method should never be called" reads better than "this method should be called zero times."
Not called with specific arguments
You can assert a method was not called with specific arguments while allowing calls with other arguments:
verifyNoInteractions(): zero activity on a mock
Use verifyNoInteractions() when a mock should not have been touched at all:
This is stronger than verify(mock, never()).someMethod() because it catches calls to any method on the mock. Use it when the entire dependency should be bypassed.
You can pass multiple mocks:
verifyNoMoreInteractions(): no unverified calls
Call verifyNoMoreInteractions() after verifying expected interactions to ensure nothing else happened:
Without it, you would miss unexpected side effects like an extra database write or an unintended audit log call.
never() vs verifyNoInteractions vs verifyNoMoreInteractions
| Method | Scope | Use Case | Fails When |
verify(mock, never()).method() | Single method | Specific method must not be called | That specific method was called |
verifyNoInteractions(mock) | Entire mock | Mock should be completely unused | Any method was called on the mock |
verifyNoMoreInteractions(mock) | Unverified calls | No surprise calls beyond what was verified | Unverified method calls exist |
verify(mock, times(0)).method() | Single method | Same as never() (less readable) | That specific method was called |
Examples
Conditional logic
Error paths
With argument captors
To verify a method was not called for some inputs while checking what it was called with for others:
With @MockBean in Spring Boot tests
In Spring Boot integration tests, verification works the same way with @MockBean:
InOrder verification with never()
When the order of interactions matters, combine InOrder with never():
Mistakes that make these tests brittle or wrong
- Using verifyNoMoreInteractions as a default in every test. This makes tests brittle: if the implementation adds a harmless extra call, such as a logging call on the mock, every test breaks. Reserve
verifyNoMoreInteractions()for tests where unexpected interactions genuinely matter, and avoid using it as a blanket assertion. - Verifying non-interaction on a real object instead of a mock. Mockito verification only works on mocks. Calling
verify()on a real instance throwsNotAMockException, so create the object withmock()or@Mock. - Forgetting argument matchers when using never().
verify(mock, never()).method("specific")only checks that exact argument and misses calls with different ones. UseanyString()orany()for broader assertions. - Confusing verifyNoInteractions with verifyNoMoreInteractions.
verifyNoInteractionsfails if any method was called at all.verifyNoMoreInteractionsfails only for calls that have not been explicitly verified. Mixing them up over-constrains or under-constrains behavior. - Not resetting mocks between tests. With shared mock instances, interactions leak from one test method into another. Use
@BeforeEachwithreset(mock)or, better, create fresh mocks per test. - Over-mocking. Verifying that ten methods were never called usually means you are testing implementation details, not behavior. Focus on the one or two non-interactions that represent real business rules.
Related reading
- How to view autoconfigure log output during spring boot tests integration tests
- How to view the list of compile errors in IntelliJ?
- How to view the SQL queries issued by JPA?
- How to wait for all threads to finish, using ExecutorService?
- How to verify that method was NOT called in Moq?
- How to wait for async mounted of Vue component to finish before continuing with testing
- How to write a proper global error handler with Spring MVC / Spring Boot
- How to write a unit test for a Spring Boot Controller endpoint
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.