Breaking Dependencies Using a Seam
Sometimes it is not possible to write tests due to excessive coupling. If your code is dealing with external dependencies, we can break the dependency to allow the Subject Under Test to be exercised independently.
If the dependency is injected through the constructor or setters, replacing the dependency with a test double should be enough. Unfortunately, that’s not always the case. Sometimes you have to deal with static dependencies or locally generated ones. In those cases, you will have to segregate the dependency, introducing a seam in your code (as specified in Working Effectively with Legacy Code by Michael C. Feathers).
In clothing, a seam joins parts together to form a piece of clothing. In code, we can use this concept to find soft points where we can separate coupled parts. If your language supports passing functions as parameters, you can use the Peel-and-Slice technique by Llewellyn Falco.
We should be extremely careful...