Unit Testing

Mockito is a mocking Framework


It allows us to easily mock objects:

mock(MyService.class) //using mock static method


@Mock +  MockitoAnnotations.initMocks(this);

We can specify the desired behavior of the mocks using Mockito’s fluent APIs:


or the equivalent:


Its also possible to verify side effects using the verify() method chains, however verify should not be a replacement for asserts (see this article).

Tagged with: , ,
Posted in JUnit, Mockito, Testing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: