Finding the right Mockito import

I really enjoy working with Mockito, it’s a fantastic mocking framework for Java. However it can be a pain sometimes to know which packages to import for the tests you are writing.

A quick tip is to import everything while writing your tests & mocks like this:

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.Matchers.*;

Then once you have completed writing your tests use the CTRL+SHIFT+O (it’s CMD+SHIFT+O on Mac) shortcut in Eclipse to breakdown your imported packages to what you actually used.

You’ll end up with something like this:

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.anyString;

Much easier yeah? 🙂

Source: Finding import static statements for Mockito constructs

Advertisements

Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

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