Testing in Isolation

When the class we want to test depends on other classes, we have two choices: test all the classes it depends on, or try to isolate it and test it in isolation. Generally, the piece of software we want to test is called system under test (SUT). Even though sometimes it makes sense to test all the dependencies together, we'll explore here a technique, called test double, to test in isolation.

The idea is to replace the dependencies with something that resembles the dependent collaborator, but that doesn't have all the logic and dependencies of the real one. The SUT has two kinds of relationships: indirect input and indirect output.

While the test itself creates the direct input and verifies the direct output, the collaborator can generate an indirect input to the SUT or receive indirect output from the SUT. The way the indirect input and output are handled defines the different type of test double.