What’s the best mock framework for Java?

Question :

What’s the best mock framework for Java?,

Answer :

What’s the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?


I’ve had good success using

When I tried learning about JMock and EasyMock, I found the learning curve to be a bit steep (though maybe that’s just me).

I like Mockito because of its simple and clean syntax that I was able to grasp pretty quickly. The minimal syntax is designed to support the common cases very well, although the few times I needed to do something more complicated I found what I wanted was supported and easy to grasp.

Read More  Memory leak detectors for C?

Here’s an (abridged) example from the Mockito homepage:

import static org.mockito.Mockito.*;    List mockedList = mock(List.class);  mockedList.clear();  verify(mockedList).clear();  

It doesn’t get much simpler than that.

The only major downside I can think of is that it won’t mock static methods.

That’s the answer What’s the best mock framework for Java?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you

Read More  Generic type checking