Understanding and using test doubles
You would rarely write a unit test without using a test double. Think of the term double in the same sense as a Hollywood stunt, where a stunt takes the place of a real actor in some situations. Test double is an umbrella term for an object that is used to replace a dependency with a test equivalent (double) for the sake of testing a SUT. They are meant to satisfy one or more of the following requirements:
Requirement 1: Enable the test code to compile.
Requirement 2: Eliminate side effects according to the unit test requirements.
Requirement 3: Embed a canned (predetermined) behavior that relates somehow to the real behavior.
Requirement 4: Take a note of and verify the activities that were exerted on a dependency within a unit test (we will name this requirement later as spying).
We will be referring to these four conditions when we discuss individual test double types, so you may want to bookmark this section.
Do you want your...