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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access