Dependency Removal

Dependencies are the single most challenging issue in legacy testing. Perhaps the greatest virtue of well-done TDD code is that the tests force individual pieces of the code to be maximally independent of each other.

Without tests, legacy code tends to be highly interdependent. This makes adding tests difficult in several ways: multiple objects might need to be created to test a single method, or it might be hard to limit a test to a true functional unit if that unit is hard to reach or encased in some massive 300-line method. There are ways to have the code we need to test be separate enough to enable the tests we must write.

Keep Things Separate

Perhaps the easiest way to keep our new code from being dependent on legacy code ...

Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.