How do you verify the behavior of a mock object in Mockito?

verify() is Mockito's mechanism for behavior verification - confirming that specific methods were called on a mock, how many times, and with what arguments.

Key Points

Example

For a NotificationService that should email a user exactly once after checkout, you'd write verify(mailSender, times(1)).send(eq("user@example.com"), any(String.class)).

@Test
void sendsWelcomeEmailOnce() {
    MailSender mailSender = mock(MailSender.class);
    UserService service = new UserService(mailSender);

    service.register("user@example.com");

    verify(mailSender, times(1)).send(eq("user@example.com"), anyString());
}

Interview Tip

A concise interview answer is

I use verify() to assert that a mock was interacted with the way I expect - a specific method, call count, and arguments - using helpers like times(), never(), and argument matchers. It's how I confirm side-effecting behavior, like sending an email, actually happened without a return value to check.

Last updated: 16 July 2026

Previous question: What are the use cases for doReturn(), doThrow(), and doAnswer() in Mockito?

Next question: How do you mock an exception using Mockito?

More Mockito interview questions

All Mockito questions