I’m investigating which mocking framework to use for my project and have narrowed it down to JMockit and Mockito.
I notice that Mockito was voted “the best mock framework for Java” on Stackoverflow.
In comparing features on JMockit‘s “Mocking Tool Comparision Matrix” it appears that JMockit has multiple different features.
Does anyone have any specific information (not opinions) on what Mockito can do which can’t be achieved with JMockit and vice versa?
Update Sep 2019: The only mocking framework supported (by default) by Spring Boot is Mockito. If you use Spring, the answer is quite obvious.
I’d say the competition is between JMockit and PowerMock, then Mockito.
I’d leave “plain” jMock and EasyMock because they use only proxy & CGLIB and do not use Java 5 instrumentation like the newer frameworks.
jMock also didn’t have a stable release for over 4 years. jMock 2.6.0 required 2 years to go from RC1 to RC2, and then another 2 years before it actually got released.
Regarding Proxy & CGLIB vs instrumentation:
The above is copied from http://jmockit.org/about.html . Further, it compares between itself (JMockit), PowerMock, and Mockito in several ways:
(granted, the source may be biased, but well…)
I’d say go with JMockit. It’s the easiest to use, flexible, and works for pretty much all cases even difficult ones and scenarios when you can’t control the class to be tested (or you can’t break it due to compatibility reasons etc.).
My experiences with JMockit have been very positive.