Autogenerate a Mock with Mock Maker
Mock objects are objects that implement no logic of their own and are used to replace the parts of the system with which the unit test interacts. In our case it is the DAO layer we would like to mock. We could write our own mock implementation, but mock maker does a very good job of autogenerating the mock for us. package bank; /** * @mock */ public interface BankAccountDAO { public void saveBankAccount(BankAccount b) throws Exception; public BankAccount getBankAccount(long a); public void removeBankAccount(BankAccount b) throws Exception; } With the @mock tag in the header mock maker generates the mock. In the example the ant target ant generate-mocks generates the mock implementation of BankAccount. Now we need to replace the DAO call to return our mock objects instead of the DAO implementation.