Testing Errors


Data Reference Errors

1. Does a referenced variable have a value that is unset or uninitialized?
This probably is the most frequent programming
error; it occurs in a wide variety of circumstances. For each
reference to a data item (variable, array element, field in a
structure), attempt to “prove” informally that the item has a
value at that point.

2. For all array references, is each subscript value within the
defined bounds of the corresponding dimension?

3. For all array references, does each subscript have an integer
value? This is not necessarily an error in all languages, but it
is a dangerous practice.

4. For all references through pointer or reference variables, is
the referenced memory currently allocated? This is known as
the “dangling reference” problem. It occurs in situations
where the lifetime of a pointer is greater than the lifetime of
the referenced memory. One situation occurs where a
pointer references a local variable within a procedure, the
pointer value is assigned to an output parameter or a global
variable, the procedure returns (freeing the referenced loca-
Program Inspections, Walkthroughs, and Reviews 27
tion), and later the program attempts to use the pointer
value. In a manner similar to checking for the prior errors,
try to prove informally that, in each reference using a pointer
variable, the reference memory exists.

5. When a memory area has alias names with differing attributes,
does the data value in this area have the correct attributes
when referenced via one of these names? Situations to look
for are the use of the EQUIVALENCE statement in FORTRAN,
and the REDEFINES clause in COBOL. As an example, a
FORTRAN program contains a real variable A and an integer
variable B; both are made aliases for the same memory area by
using an EQUIVALENCE statement. If the program stores a value
into A and then references variable B, an error is likely present
since the machine would use the floating-point bit representation
in the memory area as an integer.

6. Does a variable’s value have a type or attribute other than
what the compiler expects? This situation might occur where
a C, C++, or COBOL program reads a record into memory
and references it by using a structure, but the physical representation
of the record differs from the structure definition.

7. Are there any explicit or implicit addressing problems if, on
the machine being used, the units of memory allocation are
smaller than the units of memory addressability? For instance,
in some environments, fixed-length bit strings do not necessarily
begin on byte boundaries, but addresses only point to
byte boundaries. If a program computes the address of a bit
string and later refers to the string through this address, the
wrong memory location may be referenced. This situation
also could occur when passing a bit-string argument to a
subroutine.

8. If pointer or reference variables are used, does the referenced
memory location have the attributes the compiler expects?
An example of such an error is where a C++ pointer upon
which a data structure is based is assigned the address of a different
data structure.

9. If a data structure is referenced in multiple procedures or
subroutines, is the structure defined identically in each procedure?

10. When indexing into a string, are the limits of the string offby-
one errors in indexing operations or in subscript references
to arrays?

11. For object-oriented languages, are all inheritance requirements
met in the implementing class?
Labels: Testing
Desk Checking

Desk Checking

A third human error-detection process is the older practice of desk
checking. A desk check can be viewed as a one-person inspection or
walkthrough: A person reads a program, checks it with respect to an
error list, and/or walks test data through it.
For most people, desk checking is relatively unproductive. One
reason is that it is a completely undisciplined process. A second, and
more important, reason is that it runs counter to a testing principle of
Chapter 2—the principal that people are generally ineffective in testing
their own programs. For this reason, you could deduce that desk
checking is best performed by a person other than the author of the
program (e.g., two programmers might swap programs rather than
desk check their own programs), but even this is less effective than
the walkthrough or inspection process. The reason is the synergistic
effect of the walkthrough or inspection team. The team session fosters
a healthy environment of competition; people like to show off by
finding errors. In a desk-checking process, since there is no one to
whom you can show off, this apparently valuable effect is missing. In
short, desk checking may be more valuable than doing nothing at all,
but it is much less effective than the inspection or walkthrough.

Data-Declaration Errors

1. Have all variables been explicitly declared? A failure to do so
is not necessarily an error, but it is a common source of trouble.
For instance, if a program subroutine receives an array
parameter, and fails to define the parameter as an array (as in
a DIMENSION statement, for example), a reference to the array
(such as C=A (I)) is interpreted as a function call, leading to
the machine’s attempting to execute the array as a program.
Also, if a variable is not explicitly declared in an inner procedure
or block, is it understood that the variable is shared with
the enclosing block?

2. If all attributes of a variable are not explicitly stated in the
declaration, are the defaults well understood? For instance,
the default attributes received in Java are often a source of
surprise.

3. Where a variable is initialized in a declarative statement, is it
properly initialized? In many languages, initialization of
arrays and strings is somewhat complicated and, hence, error
prone.

4. Is each variable assigned the correct length and datatype?

5. Is the initialization of a variable consistent with its memory
type? For instance, if a variable in a FORTRAN subroutine
needs to be reinitialized each time the subroutine is called, it
must be initialized with an assignment statement rather than
a DATA statement.
Program Inspections, Walkthroughs, and Reviews 29

6. Are there any variables with similar names (VOLT and VOLTS,
for example)? This is not necessarily an error, but it should
be seen as a warning that the names may have been confused
somewhere within the program.