Setup

You now know how to craft well-designed code using TDD. But the reality for most programmers is that you’re not working on new code most of the time. Instead, you’re slogging through vast amounts of existing code that was not built using TDD—legacy code. And most of that vastness exposes a terrifying wasteland of difficult, poorly designed, hastily constructed code.

How do you begin to deal with this sea of legacy code? Can you still practice TDD in such a codebase, or is TDD applicable only to pristine codebases? In this chapter, you’ll learn some techniques that will help you begin to tackle this serious and ever-present challenge.

You’ll learn a small set of techniques and thoughts around safe refactoring of code when you don’t have tests. You’ll add tests to existing code to characterize its behavior, which will allow you to begin test-driving in any changes you need to make. You’ll learn how to use linker stubbing to help you quickly dispense with testing headaches that third-party libraries often create. Finally, you’ll learn about the Mikado Method, a technique for managing large-scale code refactoring efforts.

We’ll use CppUTest as our unit testing tool of choice as we work through the examples in this chapter. The mocking framework built into CppUTest can make it easier to deal with legacy testing challenges. You can continue to follow along with Google Test/Google Mock, if you prefer, with relatively straightforward adaptations to your unit test code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.31.67