Few days ago came in my mind the idea to measure the performance of the mocking framework used here. I was curious how it affects our unit tests' running time and how can we squeeze out some extra performance from the build agents. I created a basic measurement code with low amount of iteration steps (to imitate a medium sized codebase) and recognized we are in the world of nanoseconds. From this point all the measurement is just about some competition between the frameworks and no reason to switch between them just to make the test run faster.
I tested only three common cases:
- Mock creation
- Mock interaction
- Mock verification
Test environment: Core i5 750@2.67GHz
Here are the results
Conclusion:
Easymock dramatically overperforms Mockito even it needs a bit more coding in some cases, but the difference is not changing the game. You can use any of them without worrying for their performance
The code also available on GitHub