Next page | Contents page |

Stubs and mocks

The traditional approach to testing with dependent objects was to write stubs. In the customer/order case we would write StubOrder as a minimal implementation of Order that returns example values from its methods. It would also have to have a constructor of course.

Mock objects avoid having to write any implementations. Instead, reflection is used to create objects automatically that satisfy the interface contract.

The most popular mocking systems are JMock and EasyMock. For this course we use EasyMock.

Sometimes it is still useful to write stubs but whenever possible we use mock objects for unit testing.

Next page | Contents page |