Defect Examples: The Coin Problem
The
following examples illustrate some instances of the defect classes that were
discussed in the previous sections. A simple specification, a detailed design
description, and the resulting code are shown, and defects in each are
described. Note that these defects could be injected via one or more of the
five defect sources discussed at the beginning of this chapter. Also note that
there may be more than one category that fits a given defect. Figure 3.3 shown
a sample informal specification for a simple program that calculates the total
monetary value of a set of coins. The program could be a component of an
interactive cash register system to support retail store clerks. This simple
example shows requirements/ specification defects, functional description
defects, and interface description defects.
The
functional description defects arise because the functional description is
ambiguous and incomplete. It does not state that the input, number_of_coins,
and the output, number_of_dollars and number _of_cents, should all have values
of zero or greater. The number_of_coins cannot be negative, and the values in
dollars and cents cannot be negative in the real-world domain. As a consequence
of these ambiguities and specification incompleteness, a checking routine may
be omitted from the design, allowing the final program to accept negative values
for the input
number_of_coins
for each of the denominations, and consequently it may calculate an invalid
value for the results. A more formally stated set of preconditions and
postconditions would be helpful here, and would address some of the problems
with the specification. These are also useful for designing black box tests.
A precondition is a condition that must be true in
order for a software component to operate properly.
In this
case a useful precondition would be one that states for example:number_of_coins
__0
A postcondition is a condition that must be true
when a software component completes its operation properly.
A useful
postcondition would be: number_of_dollars, number_of_cents _0.
In
addition, the functional description is unclear about the largest number of
coins of each denomination allowed, and the largest number of dollars and cents
allowed as output values. Interface description defects relate to the ambiguous
and incomplete description of user-software interaction. It is not clear from
the specification how the user interacts with the program to provide input, and
how the output is to be reported. Because of ambiguities in the user
interaction description the software may be difficult to use. Likely origins
for these types of specification defects lie in the nature of the development
process, and lack of proper education and training. A poor-quality development
process may not be allocating the proper time and resources to specification
development and review. In addition, software engineers may not have the proper
education and training to develop a quality specification. All of these
specification defects, if not detected and repaired, will propagate to the
design and coding phases. Black box testing techniques, which we will study in
Chapter 4, will help to reveal many of these functional weaknesses. Figure 3.4
shows the specification transformed in to a design description. There are
numerous design defects, some due to the ambiguous and incomplete nature of the
specification; others are newly introduced. Design defects include the
following:
Control, logic, and sequencing defects. The
defect in this subclass arises from an incorrect while loop condition (should be less than or equal to six)
Algorithmic, and processing defects. These
arise from the lack of error checks for incorrect and/or invalid inputs, lack of a path where users can correct
erroneous inputs, lack of a path for recovery from input errors. The lack of an
error check could also be counted as a functional design
defect
since the design does not adequately describe the proper functionality for the
program. Data defects. This defect
relates to an incorrect value for one of the elements of the integer array, coin_values, which should read 1,5,10,25,50,100.
External interface description defects. These are
defects arising from the absence of input
messages or prompts that introduce the program to the user and request
inputs. The user has no way of knowing in which order the number of coins for
each denomination must be input, and when to stop inputting values. There is an
absence of help messages, and feedback for user if he wishes to change an input
or learn the correct format and order for inputting the number of coins. The
output description and output formatting is incomplete. There is no description
of what the outputs means in terms of the problem domain. The user will note
that two values are output, but has no clue as to their meaning. The control
and logic design defects are best addressed by white box- based tests,
(condition/branch testing, loop testing). These other design defects will need
a combination of white and black box testing techniques for detection. Figure
shows the code for the coin problem in a ―C-like programming language. Without
effective reviews the specification and
design defects could propagate to the code. Here additional defects have been introduced in the coding phase.
Control, logic, and sequence defects. These include the loop variable increment step which is outof the scope of the loop. Note that incorrect loop condition (i _ 6) is carried over from design and should be counted as a design defect.
Algorithmic and processin g defects. The
division operator may cause problems if negative values are divided, although this problem could be eliminated with
an input check.
Data Flow defects. The
variable total_coin_value is not initialized. It is used before it is defined.
(This might also be considered a data defect.)
Data Defects. The error in initializing the array
coin_values is carried over from design and should be counted as a design defect.
External Hardware, Software Interface Defects. The call
to the external func tion ―scanf‖ is incorrect. The address of the variable must be provided
(&number_of_coins).
Code Documentation Defects. The
documentation that accompanies this code is incomplete and ambiguous. It reflects the deficiencies in the external interface
description and other defects that occurred during speci fication and design.
Vital information is missing for anyone who will need to repair, maintain or
reuse this code.
The poor
quality of this small program is due to defects injected during several of the
life cycle phases with probable causes ranging from lack of education, a poor
process, to oversight on the part of the designers and developers. Even though
it implements a simple function the program is unusable because of the nature
of the defects it contains. Such software is not acceptable to users; as
testers we must make use of all our static and dynamic testing tools as
described in subsequent chapters to ensure that such poor-quality software is
not delivered to our user/client group. We must work with analysts, designers
and code developers to ensure that quality issues are addressed early the
software life cycle. We must also catalog defects and try to eliminate them by
improving education, training, communication, and process.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.