Write the Tests First (Sometimes)

  • Michael Stueben


In industry, the first step in testing is called domain testing: testing of variables, constraints, and correct types. Next is unit testing (aka functional testing aka white-box testing): the testing of individual functions. Finally there is black-box testing: the testing of the entire program. Industry also uses programs to test programs. In school, we generally test as we go by tracing data and checking for the expected answers. We don’t usually write other functions to test our functions. This is fine, with one exception. For a complicated algorithm, a test function should be written first—before writing the algorithm, and then another test function should be written after the writing the algorithm. That is two different test functions. You must see an example to appreciate this advice. The following code is the first test function, a smoke test, that I wrote prior to writing the binary search.

Copyright information

© Michael Stueben 2018

Authors and Affiliations

  • Michael Stueben
    • 1
  1. 1.Falls ChurchUSA

Personalised recommendations