Aug 312008
The eMock quick fix

Screenshot 1: The new 'Create Mock' quick fix

This is a very simple plugin that supports unit testing with

EasyMock. It adds a new quick fix ‘Create mock’ (accessible throgh Ctrl-1) to the Java editor in Eclipse for any identifier that cannot be resolved (see Screenshot 1).

When clicked, this quick fix (which is very similiar to the ‘Add local variable’ quick fix builtin to Eclipse) adds a createMock(..) statement to the method body and a replay(..) statement directly after (see Screenshot 2).

The result of the quick fix.

Screenshot 2: Result of the applied quick fix

As I said: very simple. However, Some experience with EasyMock has shown me that exactly this is what costs the most time when writing Unit tests: 1. Create a local variable, 2. add a createMock(..) statement, 3. add a replay(..) statement… this can get *very* annoying if you have many indirections and must mock 5 or 6 items in  a row. This plugin should take away this need and thus increase productivity.

Download the eMock plugin. Simply drop the JAR file into eclipse/plugins folder. Please be aware that this is still an early version that works only with Eclipse 3.4 ‘Ganymede’ and above.

The plugin is published under EPL. I appreciate any feedback and bug reports.