Dummy object libraries in Java

Does anyone suggest a Mock library and provide arguments for the choice?

I want to introduce it into an existing code base.

Thanks.

+4
source share
4 answers

This is the best comparison I've seen from several explicit ridiculous frameworks including EasyMock and mockito. [Original page unavailable; this link refers to an archive copy.]

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

At first I used EasyMock, but switched to Mockito. Unit tests created with EasyMock were sometimes fragile and difficult to debug. Mockito is easy, in part because it distinguishes between stubbing and verification. Here's a comparison focused on Mockito and EasyMock: http://code.google.com/p/mockito/wiki/MockitoVSEasyMock .

+10
source

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 comparative matrix .

+1
source

EasyMock. Reasons from their site

'EasyMock provides Mock Objects for interfaces (and objects through a class extension), creating them on the fly using the Java proxy mechanism. Due to EasyMock's unique waiting style, most refactoring will not affect Mock Objects. Thus, EasyMock is ideally suited for test-based development.

0
source

All Articles