Sensing and separation
Generally, when we want to get tests in place, there are two reasons to break dependencies: sensing and separation.
1. Sensing—We break dependencies to sense when we can’t access values our code computes.
2. Separation—We break dependencies to separate when we can’t even get a piece of code into a test harness to run.
There are many techniques for Separation but one dominant technique for sensing.
One of the big problems that we confront in legacy code work is dependency. If we want to execute a piece of code by itself and see what it does, often we have to break dependencies on other code. But it’s hardly ever that simple. Often that other code is the only place we can easily sense the effects of our actions. If we can put some other code in its place and test through it, we can write our tests. In object orientation, these other pieces of code are often called fake objects.
Michael, C. (2008). Feathers. Working Effectively with Legacy Code.