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().


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).


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


With EasyMock, when you "expect" you are actually record the desired fake/mocked behavior. So when you want to inject this mocked behavior onto a test runner (e.g. JUnit) you would "replay" your records.

Weird name comparing to other mocking framework indeed, a better name should be

  • expect --> register
  • replay --> activate (or no need to call this at all).