I have for long worked on EasyMocking in JUnits. I am pretty much comfortable with this but now I want to know how EasyMocks are different from Jmockits. I tried going through their documentation and I found out that the syntax is a bit different. But yet I could not figure out if there is any difference in their performances. Can anyone help me figure out what are the points that make either of them better than the other? Is there any special element in JMockit that is not found in the other? Thanks in advance...
There are many differences between JMockit and EasyMock/jMock/Mockito/PowerMock. These are the major ones:
static
methods, constructors, and "new
-ed" objects cannot be mocked at all. PowerMock supports full mocking as well, but still focused on mock objects (specifically, new-ed objects must be "replaced" with mock objects through whenNew
recording, while with JMockit a test can simply declare a @Mocked
field).final
classes and methods. Only PowerMock also provides this support. Mockito recently added an "inline mock maker" which adds support for final
s, but it's not active by default and may not be as reliable.anyString
, etc.) only for some parameters, while other mocking APIs require such matchers for every single parameter.As for performance, mocking a type with JMockit (done through class redefinition) probably has a higher runtime overhead when compared to creating a mock object with EasyMock/jMock/Mockito (done through subclass definition), and lower when compared with PowerMock (done through class definition on a custom classloader). However, you should only notice the difference in performance if there is a lot of mocking being done, which most likely indicates overuse of mocking.