Next: Large-scale testing. Up: Testing and debugging. Previous: None.
Solid testing requires the following three steps.
Testing falls into two categories: white-box testing and black-box testing.
White-box testing involves generating test cases while looking at the code. Generally, you're looking for a large enough set of test cases to hit all the cases in the code.
For example: Consider the following piece of code to find the maximum of 5 numbers typed by the user.
If we were trying to hit all execution paths, we'd have to cover all 16 combinations of hitting/missing the if condition. Such examples could include the following.int max = IO.readInt(); for(int i = 0; i < 4; i++) { int q = IO.readInt(); if(q > max) { max = q; } }
If we modified the program to find the the maximum of 20 numbers, we'd have 220 > 1 million different cases. This is just not reasonable.1 1 1 1 1 1 1 1 1 5 1 1 1 4 1 1 1 1 4 5 1 1 3 1 1 1 1 3 1 5 1 1 3 4 1 1 1 3 4 5 1 2 1 1 1 1 2 1 1 5 1 2 1 4 1 1 2 1 4 5 1 2 3 1 1 1 2 3 1 5 1 2 3 4 1 1 2 3 4 5
If you settle for the second case, then there is just one case to test: And that case must have the if condition be true at some time.
Of course, this isn't as thorough, but it at least checks the fundamentals: That the statement wasn't a complete catastrophe.1 2 1 1 1
In black-box testing, the tester generates test cases without reference to the source code - that is, the tester is treating the program as a black box, into which the tester cannot look.
Beta testing obviously always involves black-box testing. But even the original software developer does this. In fact, it's probably the primary kind of testing you've been doing on your laboratories: Once you have the program coded, you run it by acting like a regular user.
Good black-box testing will include tests falling into three categories.
For example, in the video store program, you might assume that the user always selects a customer before trying to assign a video to the currently selected customer. You ought to try running the case of trying to assign a video to the currently selected customer before any customer has been selected. Chances are good that this would crash the program.
After finding a bug in black-box testing, it's often a good idea to try to prune the test case down to try to determine exactly what's going on. You'd do this before you even begin to try to debug, because the simpler test case will generally illustrate the actual problems better.
Next: Large-scale testing. Up: Testing and debugging. Previous: None.