As we have seen, testing part of the software when it doesn't depend on other parts of the same app is quite straightforward:
- Create an instance of the class
- Set an initial context
- Trigger some behavior to change the state or to return a new set of values
This is even easier if the class being tested is well-designed and has only a single well-defined responsibility. However, it's not common to have a class that depends on other classes, or, even more complicated, a class that depends on external collaborators, such as databases, a network service, or user input.
In the next section, we'll see a technique to test this scenario. The nomenclature we use is the one defined by Gerard Meszaros in his seminal book Xunit test Patterns, Chapter 11, Using Test Doubles, and now widely used in the industry.