To Test or Not to Test

Although most of this book assumes you want or need to test your software, you should not blindly assume that is necessary. Perhaps counterintuitively, the primary purpose of automated tests is not to verify new functionality. After you create the test, each time it runs it mainly serves to verify that you did not break existing functionality.

But what if you do not care about preserving functionality? If you write code that will be thrown away, consider whether you should write automated tests for it. Prototypes, proofs of concept, demos, and experiments may all have short and limited lives.

On the other hand, code that you want to sustain should be tested. If you test your code properly, you will increase your ability ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.