Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock Object Libraries in Java

Tags:

java

mocking

Would anyone suggest a Mock library and provide the reasoning behind the pick?

I am looking to introduce one to the existing code base.

Thanks.

like image 472
Candy Chiu Avatar asked Dec 22 '22 22:12

Candy Chiu


2 Answers

This is the best comparison I've seen, of multiple Java mocking frameworks, including EasyMock and mockito. [The original page is offline; this link is to an archived copy.]

It includes EasyMock, Mockito, jMock, SevenMock, JMockit, rMock, Unitils.

I used EasyMock first, but have moved to Mockito. Unit tests created with EasyMock were sometimes fragile and hard to debug. Mockito is easy, partly because it distinguishes between stubbing and verification. Here's a Mockito-oriented comparison of it and EasyMock: http://code.google.com/p/mockito/wiki/MockitoVSEasyMock.

like image 102
Andy Thomas Avatar answered Dec 31 '22 14:12

Andy Thomas


My suggestion is JMockit (I wrote it). The project site has a lot of information (and hundreds of actual JUnit tests) comparing several Java mocking APIs (EasyMock, jMock, JMockit, Mockito, PowerMock, Unitils Mock), as well as an extensive feature comparison matrix.

like image 20
Rogério Avatar answered Dec 31 '22 13:12

Rogério