Mock objects are just fake objects that implement a required interface (or possibly a sub-class of a real class).
They usually do nothing, and return nothing when called.
For example, in
JDBC, I could make a MockResultSet that implemented every required method, but just returned null (or 0 or false).
Now when
unit testing, or in early development, I can use that MockResultSet object any place where my class needed a ResultSet. This will enable me to unit test without having to connect to a database. Of course, the mock object will not actually return any data. But I can fix that by enhancing my MockResultSet object to always return the same kind of data.
There is an open source effort at
MockObjects which is a set of mock objects specifically developed for unit testing with
JUnit. They have such things as a MockResultSet, MockHttpServletRequest, MockMessage (for JMS), and many more. People use these mock objects to test EJBs. Instead of testing your EJB client in the container, use a MockContext which returns a local implementation of the bean's interface. (Very similar to what Pradeep was talking about)
[ September 11, 2003: Message edited by: Michael Zalewski ]