Those Mocking Libraries In Full

People call them frameworks, but the way i see it, they're libraries.


Information correct as of 2011-06-12. Bold indicates a reason to seriously consider a particular library. I should really add columns for 'Mocks statics?', 'Mocks finals?', 'Strict expectations?', and various other things.

Library First Release Latest Release Google Hits Mocks Classes?
EasyMock 1.0 2003-08-17 3.0 2010-05-08 417k
jMock 1.1.0 2007-03-27 2.5.1 2008-08-24 249k ✓ (with jMock Legacy)
JMockit 0.990 2009-10 0.999.9 2011-05-17 73.1k
JMockLib (aka MockLib) 1.1.2 2005-05-08 3.1.1 2009-02-11 4.15k ?
Mockachino 0.1 2010-02-06 0.5.1 2011-01-21 2.34k ✓ (with Objenesis?)
Mockito 0.9 2008-01 1.8.5 2010-05-26 289k
Moxie 0.3 2010-07-06 0.9.0 2010-11-01 ?
RMock 1.0.0 2005-06-04 2.0.0 2007-03-18 22.5k
SevenMock 0.9 2007-11-10 2.1.0 2008-06-17 2.19k

Also, check out Powermock, which is a third-party add-on which turbocharges other libraries.


vs jMock JMockit Mockachino Mockito Moxie
EasyMock 2009-01 2010-12-17 2010-12-17 2010-06-27 2010-11-01 2010-11-01
jMock 2010-10? 2010-12-17 2010-08-01 2010-11-01
JMockit 2010-11-05
Mockachino 2010-02-21
Mockito 2010-11-01

See also some general comparisons, both definitely worth reading:

Family Tree

Most of these libraries were written as a response to the landscape of other libraries which existed at the time, in an attempt to improve on them. However, it does seem that most libraries were a response to some specific set of predecessors. Using a highly advanced guesswork-based process, i have determined that the predecessors of each library are:

original (Freeman, Mackinnon, Pryce, et al)
EasyMock, jMock, Mockito
EasyMock, JMock, Mockito

If each library was successful at improving on its predecessors, then the only libraries which have not so far been improved on are JMockit, Mockachino, and Moxie.

Questions You Should Ask

And by you, i mean me.

Proxies or bytecode weaving (and via an agent or a classloader)?
Less important than it used to be. Bytecode-based libraries are more powerful, but might be more finicky to work with.
Are expectations strict or loose?
If the class under test calls a method on a mock which has not been expected, should that cause failure or not? This is to some extent a matter of taste. Rainsberger's opinion is worth reading.
Is testing modal?
With some libraries, you have to explicitly switch from the specification phase to the execution and verification phase.
Is final verification explicit?
Do you have to make some sort of nowVerifyAllExpectations() call at the end of your test? That's easy to forget.
Do mocks actually suck?
Some say so