Chapter 8. Testing

There is no certainty that a program will run in the future—there is only the certainty that a program is running now. Even if you’ve run it once, it may not run again. Perhaps the environment will change around it so it will no longer function. Perhaps you’ll run it on a different computer, and it won’t work on the new machine.

However, there is hope—we are not doomed to endless uncertainty about the functionality of our software. The Law of Testing tells us the way out:

  • The degree to which you know how your software behaves is the degree to which you have accurately tested it.[8]

The more recently you’ve tested your software, the more likely it is that it still works. The more environments you’ve tested it in, the more certain you can be that it works in those circumstances. This is part of what we mean when we talk about the “degree” of testing—how many aspects of the software you’ve tested, how recently, and in how many different environments. In general, you could simply say:

  • Unless you’ve tried it, you don’t know that it works.

Saying “it works” is actually quite vague, though—what do you mean by “works”? What you really know when you test is that your software behaves as you intended it to. Thus, you have to know what behavior you intended. That may sound stupid and obvious, but it’s a critical fact in testing. You must ask a very precise question with every test, and get a very specific answer. The question could be something like, “What happens when a user ...

Get Code Simplicity now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.