EasyMock Verify With Examples

EasyMock Verify method is used to verify that all the stubbed methods are called and there are no unexpected calls on the mocked object.

EasyMock Verify

EasyMock verify() method has the same effect as calling verifyRecording(Object) and verifyUnexpectedCalls(Object) methods.

Let’s look at a simple example of EasyMock verify() method.

Notice that all the stubbed methods are being called after replay() method.

What if we don’t invoke a stubbed method?

It will throw AssertionError. For example, if I comment mockList.add(10) statement then below exception stack trace will be reported by JUnit.

EasyMock verify unexpected calls with Nice Mock

If the mocked object is a nice mock, then verify() method will not throw an error for unexpected method calls. However, it will throw an error if stubbed calls are not invoked.

Below code snippet for test will pass with green colors because mocked object is nice mock.

EasyMock verify() Complex Example

We can move EasyMock verify() method to the @After methods to make sure all the stubbed methods were being called.


EasyMock verify() method is used to make sure that all the stubbed methods are being utilized and there are no unexpected calls. The behavior for unexpected calls changes for nice mock objects where it doesn’t throw any error. EasyMock verify() method is very similar to Mockito verify() method.

You can checkout complete project and more EasyMock examples from our GitHub Repository.

By admin

Leave a Reply

%d bloggers like this: