I prefer EasyMock 2.3 to JMock 2 for working with Mock Objects in Java. It used to be the other way around.
The main reason is that EasyMock has support for Partial Mocking, which JMock lacks. In most other respects they are now approximately similar.
This is the technique of mocking individual methods of a real class, while leaving other methods with their normal implementation. This enables you to test interactions between methods of the same object. Once you get the hang of this technique, you discover it is extremely powerful, and it is hard to imagine mocking without it.
An EasyMock Gotcha
When EasyMock fails because you call a method too many times, the fail message can be confusing; something like…
java.lang.AssertionError:
Unexpected method call doProgrammedTurn():
doProgrammedTurn(): expected: 1, actual: 1 (+1)
…means that doProgrammedTurn() was called twice. It fails as soon as the expected count is exceeded, so presumably the bracketed value is always +1.
Update: PowerMock, a better EasyMock?
PowerMock is an EasyMock-derived tool that adds the ability to mock static, private, and final method invocations via bytecode manipulation at class load time. Im looking at switching over to it.