
24
Chapter 3    Goals of Test Automation
review all of the project’s risks and brainstorm about which kinds of risks could 
be at least partially mitigated through the use of Fully Automated Tests.
Goal: Tests as Safety Net 
When working on legacy code, I always feel nervous. By defi nition, legacy code 
doesn’t have a suite of automated regression tests. Changing this kind of code is 
risky because we never know what we might break, and we have no way of know-
ing whether we have broken something! As a consequence, we must work very 
slowly and carefully, doing a lot of manual analysis before making any changes. 
When working with code that has a regression test suite, by contrast, we can 
work much more quickly. We can adopt a more experimental style of changing 
the software: “I wonder what would happen if I changed this? Which tests fail? 
Interesting! So that’s what this parameter is for.” In this way, the automated 
tests act as a safety net that allows us to take chances.
2
The effectiveness of the safety net is determined by how completely our tests 
verify the behavior of the system. Missing tests are like holes in the safety net. 
Incomplete assertions are like broken strands. Each gap in the safety net can let 
bugs of various sizes through. 
The effectiveness of the safety net is amplifi ed by the version-control capabil-
ities of modern software development environments. A source code repository 
[SCM] such as CVS, Subversion, or SourceSafe lets us roll back our changes to 
a known point if our tests suggest that the current set of changes is affecting the 
code too extensively. The built-in “undo” or “local history” features of the IDE
let us turn the clock back 5 seconds, 5 minutes, or even 5 hours. 
Goal: Do No Harm 
Naturally, there is a fl ip side to this discussion: How might automated tests in-
troduce risk? We must be careful not to introduce new kinds of problems into 
the SUT as a result of doing automated testing. The Keep Test Logic Out of 
Production Code principle directs us to avoid putting test-specifi c hooks into 
the SUT. It is certainly desirable to design the system for testability, but any test-
specifi c code should be plugged in by the test and only in the test environment; 
it should not exist in the SUT when it is in production. 
Another form of risk is believing that some code is reliable because it has 
been thoroughly tested when, in fact, it has not. A common mistake made by 
developers new to the use of Test Doubles (page 522) is replacing too much of 
2
 Imagine trying to learn to be a trapeze artist in the circus without having that big net 
that allows you to make mistakes. You would never progress beyond swinging back and 
forth!
Also known as: 
Safety Net
Also known as: 
No Test Risk