WHAT'S THE BEST MOCK FRAMEWORK FOR JAVA?

Jessica James

Total Post:16

Points:114
Posted by  Jessica James
Java 
 781  View(s)
Ratings:
Rate this:
What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?
  1. Mayank Tripathi

    Post:397

    Points:3117
    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);
    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!