Dependency Removal

Dependencies are the 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. It might be hard to limit a test to a true functional unit if that unit is hard to reach or encased in a massive 300-line method. There are ways to have the code you need to test be separate enough to enable the tests you must write.

Keep Things Separate

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

Get Rails 5 Test Prescriptions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.