What's the best mock framework for Java?

Total Post:16

 1274  View(s)
Rate this:
What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?
  1. Post:397

    Re: What's the best mock framework for Java?

    I've had good success using Mockito..

    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.

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

    import static org.mockito.Mockito.*;
    List mockedList = mock(List.class);
    It doesn't get much simpler than that.

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