Testing: Let's Practice!
The goal of testing is to uncover bugs in our code. We have to think about:
- Things we might have forgotten to handle at all.
- Things we may have handled incorrectly.
When thinking about what cases to test, we're often in a “But what if it's…” mindset. We want to think about the edge cases, the unusual cases, the cases that might break our code. We want good coverage in that we don't want to forget to test some aspect of our code, but we also don't want to waste time repeatedly testing the same thing or testing trivial things that would only fail if the computer was very very broken.
Well, to start, I would test it on my own name and phone number!
That's as good a starting test as any! Checking the behavior on an input you understand very well, and that you think will match all of your assumptions, can be a great starting point.
But while it's fine to have a test like that, it's definitely not enough!
For sure. What else should we test?
Some people might enter their phone number with dashes between the numbers, and other people might enter it with just the numbers.
Yep. We should probably make sure the program does the right thing with both.
What if someone misses a number in their phone number?
Good point! We probably want to check the program's behavior if there's an input error like that!
Similarly, we should check names that are entered with capital letters and names that are entered in all lowercase!
Ooh! And names that aren't written in Latin characters at all!
You're getting the idea!
Other tests might depend on what, exactly, the program is doing with the name and phone number.
But thinking about what the edge cases are where the program might behave differently than we want, will serve us well on all sorts of testing.
We'll revisit this idea when we start writing our own classes in C++.
(When logged in, completion status appears here.)