Test doubles are like stunt doubles, they take the place of the 'real' thing in test code. They are particularly useful in TDD but can also help in making existing tests quicker, more reliable and more controllable.
This is a placeholder object that is passed to the SUT as an argument (or an attribute of an argument) but is never actually used.
- We can create a dummy manually
- We can create a dummy with a mocking framework
This is an object that replaces a real component on which the SUT depends so that the test can control the indirect inputs of the SUT. It allows the test to force the SUT down paths it might not otherwise exercise. Some examples are hard-coded and configurable responders and saboteurs
A Test Spy is a more capable version of a Test Stub. It can be used to verify the indirect outputs of the SUT by giving the test a way to inspect them after exercising the SUT. An example of verifying indirect outputs.
This is an object that replaces a real component on which the SUT depends so that the test can verify its indirect outputs. An example of the mock