Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is EasyMock.replay() used for?

I'm a newbie to unit testing and Junit. I know the basics of Junit. I just started learning about the EasyMock framework.

I couldn't understand the use of replay() method.

Could anyone please provide some info?

I understand the use of EasyMock.expect() and EasyMock.verify().

like image 980
Surez Avatar asked May 13 '11 04:05

Surez


People also ask

What does EasyMock Replay do?

Once created, a mock is in “recording” mode, meaning that EasyMock will record any action the Mock Object takes, and replay them in the “replay” mode. expect(…): with this method, we can set expectations, including calls, results, and exceptions, for associated recording actions.

What is the difference between EasyMock and Mockito?

Mockito supports both mocks as well as spies. Both spies and mocks perform different functions. Spy creates a partial mock object, whereas mock creates a dummy/ fake (fully mock) object of the real one. Whereas EasyMock supports only mocks.

How does EasyMock test private methods?

If you still want to use EasyMock, because changing it doesn't depend on you (work in an enterprise) you can use reflection to change the private field which your method returns, or any private field for that matter. You can have these methods in a helper class for example. And use them as needed.


2 Answers

The replay method is used to pass the mock from recording (where you record the method you expect to be called) to replaying state (where you actually test).

like image 176
Henri Avatar answered Oct 05 '22 10:10

Henri


You can remember it like this: When you write EasyMock.expect(abc.someMethod).andReturn(answer), you recorded the expected behaviour. But, when you write EasyMock.replay(abc), you are actually activating it.

I found this example very useful: http://www.tutorialspoint.com/easymock/easymock_adding_behavior.htm

like image 30
Anonymous Avatar answered Oct 05 '22 09:10

Anonymous