Legacy code is often defined as code without tests. Its age is not the real problem: difficulty reading it, possible bugs, and no reliable way to tell whether a change will break something make it risky to modify. section 4.6
To apply test-driven development (TDD) to an existing codebase, start by writing tests around the code you need to change. You may need to break dependencies before tests can protect you, so proceed more slowly; those tests and the work to enable them can pay back the effort. section 4.6.1
Treat a change as a controlled process with three phases:
- Analyze the change. section 4.6.1
- Prepare to make the change safely. section 4.6.1
- Test-drive the change until the codebase is stable again. section 4.6.1
A configuration change
Suppose a change adds a configuration parameter that switches between two behaviors. Analyze the change, prepare to make it safely, then test-drive it. section 4.6.1
Use the process diagram to follow the change from a stable codebase through analysis, preparation, and test-driving to a stable result. section 4.6.1

