Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between EasyMock.createStrictMock(class<T> x) and EasyMock.createNiceMock(class<T> x)

Tags:

java

easymock

In the API doc it is mentioned that in the strictmock order checking is enabled by default while in case of nice mock it is not . I did not get what exactly they meant by "order checking".

like image 683
Sahil Gupta Avatar asked Feb 13 '14 05:02

Sahil Gupta


People also ask

What is createNiceMock?

createNiceMock() creates a mock and sets the default implementation of each method of the mock. If EasyMock. createMock() is used, then invoking the mock method throws assertion error.

What is EasyMock expect?

The expect() method tells EasyMock to simulate a method with certain arguments. The andReturn() method defines the return value of this method for the specified method parameters. The times() method defines how often the Mock object will be called. The replay() method is called to make the Mock object available.

Which among the following are benefits of using EasyMock?

Benefits of EasyMockNo Handwriting − No need to write mock objects on your own. Refactoring Safe − Renaming interface method names or reordering parameters will not break the test code as Mocks are created at runtime. Return value support − Supports return values. Exception support − Supports exceptions.


1 Answers

If you tell a mock to expect a call to foo(), then to expect a call to bar(), and the actual calls are bar() then foo(), a strict mock will complain but a nice mock won't. That's what order checking means.

like image 163
JB Nizet Avatar answered Nov 14 '22 23:11

JB Nizet