CS 246 - Object-Oriented Software Development

Example 1: Testing a Program Manually and With Simple Automation

In the video below, we demonstrate how you can test a simple program. In this example, the program reads a number from the standard input, calculates the factorial of the number, and writes it to the standard output.

The first step is to create the test cases, i.e., decide which input values we will use for the tests. In this case, we decided to test with the values 5, 10, and zero. The second step is to generate the correct expected outputs for each one of the inputs. In this example, we had a correct version of the program as a reference, so we used it to generate the expected outputs. If the correct program was not available, then the expected outputs would have to be generated manually. Finally, we execute the program we want to test and compare the actual outputs with the expected outputs.

Example 2: Automating the Tests With bash Scripts

In the video above, testing still involved some manual procedures. Even after generating the input files and the expected output files, we still had to execute each test and each comparison, one by one.

In the example below, we automate the process further by using two scripts. The script produceOutputs automates the process of generating the expected output files based on the test cases (a collection of input files). The script runSuite automates the actual tests, by running the program with all the specified inputs, comparing the actual outputs with the expected outputs, and writing a report listing any failed tests (i.e., any case where the actual output was different than the expected output).

In CS136L, you created your own versions of the scripts produceOutputs and runSuite. (The description of how these scripts can be used for testing is available in the PDF document, produceOutputs-runSuite.pdf.) You will be able to use those scripts to help you test your programs for all assignments in this course. If you don't have these scripts, you can use the provided compiled binaries instead. They will be found in your course public repository.