- Roles of Automated Tests
- Refactorings Affecting Tests
- Another Refactoring: Extract Superclass
- What Tests Should We Add?
- When Should We Add Tests?
- Bottom Line
Refactorings Affecting Tests
Some refactorings inherently affect tests. Consider Rename Class, shown in Figure 2.
Figure 2 Rename Class.
This refactoring will affect classes that refer to C, including the tests for C, and adjust them to refer to D. To highlight this process, we can draw Figure 3.
Figure 3 Rename Class showing a client.
But some refactorings don't inherently affect the clients of a class they change. Consider Extract Class, which splits a class into two parts, introducing a new class (see Figure 4).
Figure 4 Extract Class.
When we include the test class, it looks like Figure 5.
Figure 5 Extract Class showing a test client.
The tests will call the same method body (indirectly); it's just moved to a different class.