tags:

views:

82

answers:

3

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.

A: 

easymock. Reasons, from their site

'EasyMock provides Mock Objects for interfaces (and objects through the class extension) by generating them on the fly using Java's proxy mechanism. Due to EasyMock's unique style of recording expectations, most refactorings will not affect the Mock Objects. So EasyMock is a perfect fit for Test-Driven Development.'

hvgotcodes
+3  A: 

This is the best comparison I've seen, of multiple Java mocking frameworks, including EasyMock and mockito.

http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html

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.

Andy Thomas-Cramer
That comparison is very outdated. For example, the version of JMockit it evaluates is almost three years old now. The author actually promised to update it, but never came through.
Rogerio
@Rogerio - You should disclose that you are the author of JMockit.
Andy Thomas-Cramer
It is disclosed. My SO profile contains a link to the JMockit project site, which in turn reveals my full name. I simply find it annoying and redundant to include an explicit note about that in every post I make concerning JMockit.
Rogerio
A: 

My suggestion is JMockit. 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.

Rogerio
It is misleading to recommend your own product without disclosing yourself as the author.
Andy Thomas-Cramer
Hmm, I don't know... why do you consider it misleading, exactly? Anyone can easily discover that by checking my name here and on the project site; my identity has never been hidden. (I am not saying you're wrong, necessarily; just trying to better understand the point of view.)
Rogerio
Most people do not read your profile. There is one author and n users. In the absence of other information, it is most likely that a recommendation is coming from a user. It is ethical to disclose openly that you have a conflict of interest. This is why, for example, you see ethical news media including disclosures within news stories, rather than somewhere else that some subset of readers may stumble across ... like, say ... in an unused lavatory with a sign that says "beware of the tiger."
Andy Thomas-Cramer