[an error occurred while processing this directive]
Testing and debugging
"If debugging is the process of removing bugs, then programming
must be the process of putting them in." --annon.
Program Trace
A trace of a program consists of a listing of the
values of each variable at each point in the execution of the program.
- Useful, but only on small programs.
- Stub programs let larger systems be debugged and tested as
they are being built, a small portion at a time. Major program
connections are tested first, which means that major bugs and
shortcomings are detected early in the game. Furthermore, testing and
debugging are distributed throughout the entire implementation. Even
if a program isn't completely finished by the due date it's a
preliminary working version--and not just a useless mess of code.
Walkthrough
Working on a program tends to create a mind set in the programmer that
renders obvious mistakes invisible. Merely explaining a program aloud
can give a totally new view of it. A walkthrough is
an explanation and defense of the program's algorithm and
implementation to an audience.
Program Animation/Instrumentation
Program animation/instrumentation is a way to inspect a program while
it is running.
- It differs from tracing in that the values of selected
variables are printed at specific points in the program.
- Often procedures are built into programs to assist in testing
a program and left behind in case they're needed again.
- Two common techniques are probes and assertions.
Program Probes
- A program probe
- is an output statement
added to a program to print the value of a variable or to indicate the
progress of execution.
-
The output statements are probes into the program which serve to
animate it, helping to isolate the program errors.
- A simple program probe often takes the following form:
debug == TRUE;
...
if (debug) printf("debug: calling foo(%d,%d)\n",i,j);
...
Program Assertions
Often the particular value of a variable is not as important as
whether or not it meets some particular constraint (e.g. positive).
- Statements which express such constraints are called
assertions -- boolean expressions which should be
true at a particular point in a program.
- A probe which prints an error message only when variable fails
to meet the constraint can be written as follows:
void assertion(bool test, string message) {
if (debug && not(test) printf("Assertion failed: %s\n", message);
}
- Then a statement like the following can be inserted into the
appropriate point in the code:
assertion(X>=0,"X is negative");
Test Harnesses
A test harness is a program shell that is used to
test procedures in isolation, before they are integrated into a more
complex final program.
- Used especially in bottom up programming.
- A program is a delivery system for procedure calls. A test
harness is precisely that--a delivery system for procedure tests that
contains:
- the type definitions;
- procedures that initialize and/or inspect data structures; and
- the new procedure that is undergoing testing or modification.
- The new procedure can be tested without having to deal with a
main program that is more complex and finicky than the harness
is. Once it works, the new procedure can be transferred to the main
program.
Integration Testing
Testing to check that modules combine together correctly. In
addition, there should be a final product test and acceptance testing
by the client.
Regression Testing
Testing that is performed to insure that modifications to a program
have not modified previously correct behavior. This requires a
collection of test data be maintained for the purpose of regression
testing.
Some portions are adapted from Oh! Pascal third edition and notes by
Anthony Aaby, aabyan@wwc.edu.
[an error occurred while processing this directive]
Friday, 07-Mar-1997 08:10:16 EST