Intent Build confidence by making sure that whatever worked before still works.
How can you be sure that the last change you made won’t break the system?
This problem is difficult because:
- In a complex system, small changes can have unexpected side effects. A seemingly innocuous change may break something without this being immediately discovered.
Yet, solving this problem is feasible because:
- You have written test suites that express how the system should behave.
Run your regression test suite every time you think you have reached a stable state.
- It is easier to Always Have a Running Version.
- It is easier to Build Confidence as you proceed.
- You must relentlessly write the tests.
- The legacy system may not have adequate regression tests defined. To enable evolution, you will have to Grow Your Test Base Incrementally.
- Tests can only show that defects are present, not that they are absent. You may have failed to test precisely the aspect that you have broken.
- Run the tests may be very time-consuming, so you might want to run only those tests that you think might be affected by your change. Categorize your tests to avoid “ad hoc” testing of changes, but run all the tests at least once a day.
Regression tests tell you that whatever ran before still runs. If you consistently build up tests for defects you discover and new features, you will end up with a reusable test base that gives you confidence that your changes are sound, and helps you detect problems earlier.
Davis advocates “Regression Test After Every Change” [Dav95] as standard Software Development practice.
You should have already started to Write Tests to Enable Evolution.
A common practice in Extreme Programming is to write tests before you implement new functionality [JAH01]. In the context of reengineering, you should consider writing tests that will fail before you make a change, and will pass if the change is correctly implemented. (Unfortunately it is not generally possible to design tests that will only pass if the change is correct!)
Regression tests should help you to Retest Persistent Problems.