2 Minutes To Code (β Version)

Easymock - 2 minute tutorial

Overview of Easymock framework

Easymock is used to mock java classes for testing purposes.

Let me explain with an example. Suppose you write an explanation which will need to connect to DB and update tables and also hit an http server, both of which are either cumbersome to set-up or are managed by some other teams. Even then, you need to be able to test your application. Easymock, or other mocking frameworks (like Mockito ) come to your rescue.

When you mock a class, you are actually creating a duplicate of that class, and then re-defining method to bypass the actual db connection/http connection and instead return dummy responses or objects which you are expecting the db layer/http server to return anyways. If you works fine with these dummy objects, then when the actual db layer/http server rae plugged in, the application will work as expected.