Working Effectively with Legacy Tests
At the Agile Cambridge conference on the 1st of October, Duncan McGregor and I are running a workshop entitled Working Effectively with Legacy Tests.
Legacy what‽
In Working Effectively with Legacy Code, Michael Feathers defined "legacy code" as "code without tests". But not all test code is a panacea. I have often encountered what I can only describe legacy tests.
I define legacy tests as:
You have legacy tests if you usually change the code then fix the tests to match the code
Legacy tests are still useful. They reduce risk by catching unexpected regressions. But it is often difficult to know why a regression occurs and time is wasted diagnosing the underlying problem. Legacy tests don't pull their weight. They add a continual overhead to every change you make.
Symptoms of legacy tests I have encountered include:
- Programmers have to read the production code to work out what the system does, rather than the tests.
- When a test fails programmers usually have to fix the test, not production code.
- When a test fails programmers have to step through code in the debugger to work out what failed.
- It takes a lot of effort to write a test, and after a few tests, writing another test isn’t any easier.
- Programmers have to carefully study the code of a test to work out what it is actually testing.
- Programmers have to carefully study the code of a test to work out what it is not testing.
- Tests are named after issue identifiers in the company's issue tracker. Bonus points if the issue tracker no longer exists.
- Test failures are ignored because the team expect them to be transient or meaningless.
Does any of that sound familiar? If so, please bring some examples of your tests to our workshop.
We will run the workshop as a cross between a mob programming session and a clinic. Bring some legacy tests from your own projects. We will work together, in a mob programming style, to improve them. Along the way we will share techniques for writing effective tests and refactoring tests from burdensome legacy to a strategic asset.