Test Driven Development: Mocks
The importance of dummies, mocks, stubs, and fakes is fundamental to test-driven development.
Dummy objects are passed around but never actually used. Usually, they’re simply used to fill parameter lists.
Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
Stubs provide answers to calls made during the test, usually not responding to anything outside what’s programmed for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it ‘sent’ or only how many messages it ‘sent’.
Mocks are what we’re talking about here. Mocks are objects pre-programmed with expectations forming a specification of the calls they expect to receive.