Chapter 8: Testing and Debugging

Chapter Goals

Unit Tests

Unit Tests (sqrtest1.cpp)



You need to enter inputs and to force an end of input when you are done, by typing a key such as Ctrl+Z or Ctrl+D. For each test case, the harness code calls the squareroot function and prints the result. You can then manually check the computations.

Unit Tests (sqrtest2.cpp)



We generate test cases automatically and check the results manually.

Unit Tests (sqrtest3.cpp)



Random generation of test cases is useful for testing.

Selecting Test Cases


Test Case Evaluations


Assertions (reminder)


Program Traces

Program Traces (Problems with Trace Messages)


The Debugger

Detailed explanations will be given at the workshop.