Mockito for Efficient Test Double Creation

Writing a mock with Mockito

Mockito can create mock objects just as easily as stubs. We can still use the @Mock annotation on a field we wish to become a mock – perhaps making sense of the annotation, at last. We use the Mockito verify() method to check that our SUT called an expected method on a collaborator. Let’s look at how a mock is used. We’ll write a test for some SUT code that we expect to send an email via MailServer:

Get hands-on with 1200+ tech skills courses.