View all services
Talk to QA Advisor
Browse the Knowledge Hub211 resources
/Books/Working Effectively with Legacy Code
Books · Honest notes

Working Effectively with Legacy Code: is it worth reading?

How to get untested code under test, which is the situation almost every real codebase is actually in.

We earn nothing from any link on this page. No affiliate links anywhere in this library.

published
2004
key ideas
3
reading path
1

Reviewed by Viral Patel

Co-Founder, QAble

Cover of Working Effectively with Legacy Code
Legacy codeUnit testing & TDD

Working Effectively with Legacy Code

by Michael C. Feathers

Publisher
Prentice Hall
Year
2004
ISBN
9780132931755

Useful when you are: Practising tester, Senior / lead

Verdict

Should you read it?

Read it if

You work on a system you did not write that has little or no test coverage. That is most people, and this book is the single most useful thing they could read.

Skip it if

You work exclusively greenfield, which almost nobody does for long.

If you only read one thing

The chapter on characterisation tests. It is the technique that unblocks people most often, and it can be applied the day you read it.

The argument

What it argues

Feathers defines legacy code as code without tests, which is a deliberately provocative definition and a useful one: it makes the problem tractable rather than a matter of age or style.

The central difficulty is circular. To change code safely you need tests; to write tests you usually need to change the code to make it testable. The book is essentially a catalogue of techniques for breaking that cycle: seams where behaviour can be intercepted, dependency-breaking techniques, and characterisation tests that document what the code currently does rather than what it should.

It is the most practically useful book on this list for anyone working on an existing system, which is almost everyone.

Key ideas

Ideas worth taking from it

  1. 01

    Legacy code is code without tests

    A definition that reframes the problem from a quality judgement into a tractable engineering task.

  2. 02

    Seams

    A place where behaviour can be changed without editing in that place. The conceptual tool that makes dependency breaking systematic rather than ad hoc.

  3. 03

    Characterisation tests

    Tests that capture what the code currently does, including its bugs, so you can refactor safely. You are not asserting correctness, you are pinning behaviour.

Criticism

What has dated, and what it gets wrong

The examples are predominantly Java and C plus plus, and some dependency-breaking techniques are unnecessary in languages with better testing tooling or in codebases using dependency injection throughout. It is also long, and reads as a catalogue rather than a narrative. Still worth it.

Reading paths

On our reading paths

Becoming an automation engineer

Book 4 of 5 · Automation and SDET

Most automation work happens on code that was never written to be tested. This is the manual for breaking dependencies safely so tests can go in.

  1. Cover of Test Driven Development: By Example1. Test Driven Development: By Example
  2. Cover of Unit Testing Principles, Practices, and Patterns2. Unit Testing Principles, Practices, and Patterns
  3. Cover of Growing Object-Oriented Software, Guided by Tests3. Growing Object-Oriented Software, Guided by Tests
  4. Cover of Working Effectively with Legacy Code4. Working Effectively with Legacy Code (this book)
  5. Cover of Specification by Example5. Specification by Example

Keep reading

What to read next

Ready

Reading about quality is cheaper than learning it in production.

QAble runs QA for products in BFSI, gaming, healthcare and SaaS, with engineers who have read these and argued about them. Start with a free QA audit.

Talk to QA Advisor