Others have defined four types of test doubles which are often colloqually referred to as mocking, mock objects, etc.
- Dummy objects are passed around but never actually used. Usually they are just 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 canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.
- Mocks objects are pre-programmed with expectations which form a specification of the calls they are expected to receive.
- A function you need to call is time-variant.
- You want to produce an outcome that is difficult to setup, for example, a race condition.
- Tight Coupling
- Tests that really on mocking are likely to be testing implementation rather than behavior.
- Changing the implementation often requires re-working the test.
- Tests that really on mocking need to make sure that they will fail if the implementation changes in a way that bypasses
- Global State, Spooky Action at a Distance