CS 70

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.

​Suppose we have a program that takes a name and phone number as input. It isn't practical to test every single possible input. What are some inputs you would definitely want to test?

What do you think? What inputs would you want to check to test the behavior of this program?

  • Dog speaking

    Well, to start, I would test it on my own name and phone number!

  • LHS Cow speaking

    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.

  • RHS Cow speaking

    But while it's fine to have a test like that, it's definitely not enough!

  • LHS Cow speaking

    For sure. What else should we test?

  • Cat speaking

    Some people might enter their phone number with dashes between the numbers, and other people might enter it with just the numbers.

  • LHS Cow speaking

    Yep. We should probably make sure the program does the right thing with both.

  • Duck speaking

    What if someone misses a number in their phone number?

  • LHS Cow speaking

    Good point! We probably want to check the program's behavior if there's an input error like that!

  • RHS Cow speaking

    Similarly, we should check names that are entered with capital letters and names that are entered in all lowercase!

  • Dog speaking

    Ooh! And names that aren't written in Latin characters at all!

  • LHS Cow speaking

    You're getting the idea!

  • RHS Cow speaking

    Other tests might depend on what, exactly, the program is doing with the name and phone number.

  • LHS Cow speaking

    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.

  • RHS Cow speaking

    We'll revisit this idea when we start writing our own classes in C++.

(When logged in, completion status appears here.)