UNIHIVE

Study Hub UNIPORT CSC 288

CSC 288 · Structured Programming

Testing, debugging, code inspection and verification

Kinds of error, test plans and test data, black-box and white-box testing, debugging methods, inspections and proving programs correct.

Our notes

2 min read

Kinds of error

  • Syntax (compile-time) errors: breaking the language rules (missing semicolon, undeclared name). The compiler reports them.
  • Run-time errors: the program stops while running (division by zero, file not found, array index out of range).
  • Logic errors: the program runs but gives wrong answers (using > instead of >=). The hardest to find.

Test construction

A test plan lists, for each test: the purpose, the input data, the expected output (worked out beforehand) and the actual output.
Choose test data of three kinds:

  1. Normal: typical valid values (score 65).
  2. Boundary (extreme): at and just around the limits (0, 39, 40, 100).
  3. Erroneous: invalid values that must be rejected (−5, 101, "abc").

Worked example: test data for the grading program

InputExpectedReason
75Anormal
70Aboundary, lowest A
69Bboundary, just below A
40Elowest pass
39Fjust below pass
0Flowest valid
100Ahighest valid
101rejectedinvalid

Many bugs live at boundaries, which is why most of the tests are there.

Black-box and white-box testing

  • Black-box (functional): test from the specification without looking at the code: equivalence classes and boundary values.
  • White-box (structural): design tests from the code so every statement and every branch runs at least once (statement and branch coverage).

Levels of testing

Unit (each module, with drivers and stubs), integration (modules together), system (the whole program), acceptance (by the user).

Debugging

  1. Reproduce the error reliably.
  2. Narrow it down: print the values of key variables (trace statements), or use the debugger to step through, set breakpoints and watch variables (Turbo and Free Pascal IDEs have these).
  3. Form a hypothesis, fix, and re-run all the tests (regression testing), since a fix can break something else.

Code inspection and walkthroughs

Programmers read the code together, line by line, against a checklist (initialised variables, loop bounds, parameter types). Inspections find many errors before the program is ever run, cheaply.

Verification

Testing can show the presence of bugs, never their absence (Dijkstra). Verification proves a program meets its specification using assertions and invariants (see the loop invariant topic). It is used for small, critical pieces of code.

Exams usually ask

  • Distinguish syntax, run-time and logic errors with examples.
  • Construct a test plan with normal, boundary and erroneous data.
  • Compare black-box and white-box testing; describe debugging methods.

Common mistake

Testing only with "nice" data. A program that works for 65 may fail at 40 or crash on letters; boundary and invalid data find the real bugs.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 288 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.