liveBook · Manning

Legacy code

As explained in Test Driven: Practical TDD and Acceptance TDD for Java Developers

Legacy code is existing software that must be maintained or changed, often with limited tests or a design that makes changes difficult.

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:

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

Figure 4.7. The process of working with legacy code

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

How Test Driven: Practical TDD and Acceptance TDD for Java Developers covers it

How deep it goes
Defines legacy code and outlines three change phases, without specifying the individual procedures for those phases.
Examples
Uses a new configuration parameter that switches between two alternative behaviors as a motivating change.
What it assumes
Assumes an existing codebase and a requested change, and calls for tests around the code being changed.
What you can do after
Apply test-driven development to changes in an existing codebase by testing the target code and proceeding through analysis, preparation, and test-driving.
How it connects
Connects legacy code with test-driven development and software testing.

Also explained in

Compare how 2 books explain legacy code →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Test Driven: Practical TDD and Acceptance TDD for Java Developers. The section links point to the parts of the book it draws on.