Home > Articles > Programming

  • Print
  • + Share This
From the author of

Refactorings Affecting Tests

Some refactorings inherently affect tests. Consider Rename Class, shown in Figure 2.

Figure 2Figure 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 3Figure 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 4Figure 4 Extract Class.

When we include the test class, it looks like Figure 5.

Figure 5Figure 5 Extract Class showing a test client.

The tests will call the same method body (indirectly); it's just moved to a different class.

  • + Share This
  • 🔖 Save To Your Account