Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (46k points)

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

1 Answer

0 votes
by (3.4k points)

I've had achievement practicing Mockito.

When I decided to learn concerning JMock and EasyMock, I obtained the learning curve to be a bit abrupt (though perhaps that's only me).

I like Mockito because of its easy and tidy syntax that I was ready to grasp pretty quickly. The minimal syntax is intended to promote the common cases very fine, although the few times I wanted to do something more complex I found what I needed was supported and easy to grasp.

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

import static org.mockito.Mockito.*;

List mockedList = mock(List.class);

mockedList.clear();

verify(mockedList).clear();

It doesn't get much easier than that.

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...