Software Engineering Project Lecture: Debugging and Program Testing
Debugging and program testing are really the same topic.  I have separated the topics into debugging, practical advice for debugging an assignment, and formal program testing, discusses formal terms and industry techniques.

Debugging:
There are three basic errors:

  1. Syntax/compilation error
  2. Run-time exception error
  3. logic error
What to do if you get an error:  Sayings to remember:


Syntax/compilation error
Error during compiling, prevents getting a compiled code.  Modern compilers indicate well the location of the error.  Sometimes problems with delineators such as semi-colons in C or brackets in C++ or Java are not detected for many lines or at the end of the class definition or end of the program.  In the Bash scripting language missing do or done can be big problem.  The difficulty is that compiler misses the error long pass where the missing delineator is required.

Run-time Exception error
When you get an error message while running the compiled code.  Java gives good error messages indicating the location of the error but that might not be the location of  the actual error.  Some languages, such as C seem to have only one type of error; Segmentation Fault, or Fortran, index out of bounds.

Common Run-time Exception error:
 

Error message Common Cause
Null pointer exception java: Never instantiated reference, 
c: Never assigned pointer
Out of memory  Infinite loop or recursion. 
c++: Memory leak
Index out of bounds Check for loops or while bounds
Deference error java: Improper casting
Divide by zero Check arithmetic, maybe never set denominator 
Some c-compiler initially sets memory to zero

The art of debugging is essentially learning a table like the above, which helps you locate the error.  If have any strange errors and discover the cause of the error please tell me about it so I can add it to the table.

Logical Error:
Theses errors are the hardest to correct or detect.  The program "runs" but the output is not correct.

Tools for Detecting and fixing logical error:

  1. Choose test cases well.  Try to cover everything with small cases.  Try one big case.
  2. Print intermediate value.  Use a boolean variable to turn on and off debug printing.
  3. Walk though.  Play computer in front of an audience (if you can) and suspect all code especially uncommitted code.
Logical errors generally occur at: Formal Program Testing:
The software industry is primarily concern with logical errors and hidden run-time errors.  Companies expend enormous effort to find the errors before the release.  To fix a bug after the release cost a 100 times more; patches must be designed and ship out.  Besides the customer are not very happy.  Software companies generally have a special team for code test, besides allocating time for program testing.  Beta releases are distributed for evaluation by the end user.

The industry is concerned with Verification and Validation:

Testing and inspection are the primary technique for V and V: Testing:
You can do component testing in your programs.  There are basically two types of testing technique black box and white box.