mockito/mockito · error · NoInteractionsWanted

No interactions wanted here: ${location} But found these int

Error message

No interactions wanted here:
${location}
But found these interactions on mock '${mockName}':
${locations}
${scenario}

What it means

Mockito throws NoInteractionsWanted when verifyNoInteractions(mock) is called but the mock recorded at least one invocation. The NoInteractions verification mode checks data.getAllInvocations() and, if any exist, reports the first one. It is a test-assertion failure indicating the mock was used when the test expected it to be completely untouched.

Source

Thrown at mockito-core/src/main/java/org/mockito/internal/verification/NoInteractions.java:22

 */
package org.mockito.internal.verification;

import static org.mockito.internal.exceptions.Reporter.noInteractionsWanted;

import java.util.List;

import org.mockito.internal.verification.api.VerificationData;
import org.mockito.invocation.Invocation;
import org.mockito.verification.VerificationMode;

public class NoInteractions implements VerificationMode {

    @Override
    @SuppressWarnings("unchecked")
    public void verify(VerificationData data) {
        List<Invocation> invocations = data.getAllInvocations();
        if (!invocations.isEmpty()) {
            throw noInteractionsWanted(invocations.get(0).getMock(), (List) invocations);
        }
    }
}

View on GitHub (pinned to 5a676bcd9e)

Solutions

  1. Move verifyNoInteractions(mock) earlier or remove code paths that touch the mock
  2. Check the 'found this interaction' location in the message and eliminate that call in the code under test
  3. Replace verifyNoInteractions with verify(mock, never()).someMethod() if only one method should not be called
  4. Split the test so setup steps that must use the mock don't pollute the verification scope

Example fix

// before
svc.process(mock);
verifyNoInteractions(mock);
// after
verifyNoInteractions(mock); // assert before exercising, or drop the unwanted call
svc.process(mock);
Defensive patterns

Strategy: validation

Validate before calling

if (!mockitoTestingInternalUtil.getInvocations(mock).isEmpty()) { throw new AssertionError("mock already used before verifyNoInteractions"); }

Type guard

boolean isUnused(Object mock) { return Mockito.mockingDetails(mock).getInvocations().isEmpty(); }

Try / catch

try { verifyNoInteractions(mock); } catch (NoInteractionsWanted e) { fail("unexpected interaction: " + e.getMessage()); }

Prevention

When it happens

Trigger: Calling verifyNoInteractions(mock) (or Mockito.verifyZeroInteractions in older versions) after the code under test already called any method on the mock, including auto-invocations like toString/hashCode/equals or stubbing setup leaks.

Common situations: Verifying no-interactions too late in the test after helper code touched the mock; production code has a new/changed call path that now uses the mock; using the mock for stubbing with doReturn then forgetting the mock was partially invoked; calling verifyNoInteractions on a mock shared across test setup steps.

Related errors


AI-assisted analysis of mockito/mockito@5a676bcd9e (2026-09-05). Data as JSON: /api/errors/e450a4defebb177b. Report an issue: GitHub.