Testing 2
Testing 2
UNIT II
Introduction to Testing Design Strategies
• The Smart Tester
• Test Case Design Strategies
• Using Black-Box approach to Test Case Design
– Random Testing
– Equivalence Class Partitioning
– Boundary Value Analysis
– Decision tables
– Requirements based
– Positive & Negative Testing
– Cause effect Graphing
– Partitioning State Based Testing
– Error Guessing
– Compatibility Testing
– User Documentation Testing
– Domain Testing
The Smart Tester
Test Case Design Strategies
Using Black-Box approach to Test Case Design
✓ Random Testing
• Are the three values adequate to show that the module meets
its specification when the tests are run? Should additional or
fewer values be used to make the most effective use of
resources?
• Are there any input values, other than those selected, more
likely to reveal defects? For example, should positive integers
at the beginning or end of the domain be specifically selected
as inputs?
• Should any values outside the valid domain be used as test
inputs? For example, should test data include floating point
values, negative values, or integer values greater than 100?
Equivalence Class Partitioning
The tester and the analyst interact during the analysis phase to
develop -
(i) a set of testable requirements, and
(ii) a correct and complete input/output specification.
From these the tester develops -
(i) a high-level test plan, and
(ii) a preliminary set of black box test cases for the system.
Both the plan and the test cases undergo further development in
subsequent life cycle phases.
important points related to equivalence class partitioning
• The tester must consider both valid and invalid equivalence
classes. Invalid classes represent erroneous or unexpected
inputs.
• Equivalence classes may also be selected for output
conditions.
• The derivation of input or outputs equivalence classes is a
heuristic process.
• Some conditions only give the tester guidelines for
identifying the partitions. (Discuss later)
• In some cases it is difficult for the tester to identify
equivalence classes.
Equivalence Class Partitioning
E.g.
✓ Suppose the specification for a module says that an input, the length of a
widget in millimeters, lies in the range 1–499;
Then select one valid equivalence class that includes all values from 1 to
499. Select a second equivalence class that consists of all values less than
1, and a third equivalence class that consists of all values greater than 499.
✓ If the specification for a paint module states that the colors RED, BLUE,
GREEN and YELLOW are allowed as inputs, then select one valid
equivalence class that includes the set RED, BLUE, GREEN and YELLOW,
and one invalid equivalence class for all other inputs.
✓ If the specification for a module states that the first character of a part
identifier must be a letter, then select one valid equivalence class where
the first character is a letter, and one invalid class where the first character
is not a letter.
Boundary Value Analysis
• With experience, testers soon realize that many defects occur
directly on, and above and below, the edges of equivalence
classes.
• equivalence class partitioning directs the tester to select test
cases from any element of an equivalence class,
• boundary value analysis requires that the tester select
elements close to the edges, so that both the upper and lower
edges of an equivalence class are covered by test cases.
The rules-of-thumb boundary value analysis -
1. If an input condition for the software-under-test is specified
as a range of values, develop valid test cases for the ends of
the range, and invalid test cases for possibilities just above
and below the ends of the range.
2. If an input condition for the software-under-test is specified
as a number of values, develop valid test cases for the
minimum and maximum numbers as well as invalid test cases
that include one lesser and one greater than the maximum
and minimum.
3. If the input or output of the software-under-test is an
ordered set, such as a table or a linear list, develop tests that
focus on the first and last elements of the set.
Boundary Value Analysis
Example
Other Black Box Test Design Approaches
There are alternative methods to equivalence class
partitioning/boundary value analysis that a tester can use to
design test cases based on the functional specification for the
software to be tested.
• Cause-and-effect graphing
• State transition testing
• Error guessing.
Cause-and-effect graphing
• A major weakness with equivalence class partitioning is that it
does not allow testers to combine conditions.
• Cause-and-effect graphing is a technique that can be used to
combine conditions and derive an effective set of test cases that
may disclose inconsistencies in a specification.
• The specification must be transformed into a graph that
resembles a digital logic circuit.
• The tester should have knowledge of Boolean logic.
• The graph must be converted to a decision table that the tester
uses to develop test cases.
The steps in developing test cases with a cause-and-effect graph are
1. The tester must decompose the specification of a complex software
component into lower-level units.
2. For each specification unit, the tester needs to identify causes and their
effects.
• A cause is a distinct input condition or an equivalence class of input
conditions.
• An effect is an output condition or a system transformation.
3. From the cause-and-effect information, a Boolean cause-and-effect graph is
created.
• Nodes in the graph are causes and effects.
• Causes are placed on the left side of the graph and effects on the right.
• Logical relationships are expressed using standard logical operators such
as AND, OR, and NOT, and are associated with arcs.
4. The graph may be annotated with constraints that describe combinations of
causes and/or effects that are not possible due to environmental or
syntactic constraints.
5. The graph is then converted to a decision table.
6. The columns in the decision table are transformed into test cases.
Samples of cause-and-effect graph notations.
EXAMPLE
Suppose we have a specification for a module that allows a
user to perform a search for a character in an existing string.
The specification states that the user must input the length of
the string and the character to search for. If the string length is
out-of-range an error message will appear. If the character
appears in the string, its position will be reported. If the
character is not in the string, the message “not found” will be
output.
Figure 5.2
Figure 5.3
• There are commercial tools that will generate control flow
graphs from code and in some cases from pseudo code.
• The tester can use tool support for developing control flow
graphs especially for complex pieces of code.
• A control flow representation for the software under test
facilitates the design of white box–based test cases as it clearly
shows the logic elements needed to design the test cases
using the coverage criterion of choice.
Covering Code Logic
• testers can use the concepts and tools to decide on the target
logic elements and the degree of coverage that makes sense
in terms of the type of software, its mission or safety
criticalness, and time and resources available.
• For example, if the tester selects the logic element “program
statements,” this indicates that she will want to design tests
that focus on the execution of program statements.
• If the goal is to satisfy the statement adequacy/ coverage
criterion, then the tester should develop a set of test cases so
that when the module is executed, all (100%) of the
statements in the module are executed at least once.
• In terms of a flow graph model of the code, satisfying this
criterion requires that all the nodes in the graph are exercised
at least once by the test cases.
• If the tests achieve this goal, the test data would satisfy the
statement adequacy criterion.
Paths: Their Role in White Box–Based Test Design
• In previous Section the role of a control flow graph as an aid
to white box test design was described.
• It was also mentioned that tools were available to generate
control flow graphs.
• These tools typically calculate a value for a software attribute
called McCabe’s Cyclomatic Complexity V(G) from a flow
graph.
• The cyclomatic complexity attribute is very useful to a tester.
• The complexity value is usually calculated from the control
flow graph (G) by the formula
V(G) = E - N + 2
E = 7, N = 6
V(G) = 7 - 6 + 2 = 3
1-2-3-4-8
• Cyclomatic complexity is a measure of the number of so-
called “independent” paths in the graph.
• An independent path is a special kind of path in the flow
graph.
• Deriving a set of independent paths using a flow graph can
support a tester in identifying the control flow features in the
code and in setting coverage goals.
Paths: Their Role in White Box–Based Test Design
• A tester identifies a set of independent paths for the software
unit by starting out with one simple path in the flow graph
and iteratively adding new paths to the set by adding new
edges at each iteration until there are no more new edges to
add.
• The independent paths are defined as any new path through
the graph that introduces a new edge that has not be
traversed before the path is defined.
• A set of independent paths for a graph is sometimes called a
basis set.
• For most software modules it may be possible to derive a
number of basis sets.
Paths: Their Role in White Box–Based Test Design
• If we examine the flow graph in Figure 5.3, we can derive the
following set of independent paths starting with the first path
identified above.
(i) 1-2-3-4-8
(ii) 1-2-3-4-5-6-7-4-8
(iii) 1-2-3-4-5-7-4-8
• If we prepare white box test cases so that the inputs cause the
execution of all of these paths, we can be reasonably sure
that we have achieved complete statement and decision
coverage for the module.
• Testers should be aware that although identifying the
independent paths and calculating cyclomatic complexity in a
module of structured code provides useful support for
achieving decision coverage goals, in some cases the number
of independent paths in the basis set can lead to an over
approximation of the number of test cases needed for
decision (branch) coverage.
Paths: Their Role in White Box–Based Test Design
• One additional logic-based testing criterion based on the path
concept should be mentioned.
• It is the strongest program-based testing criterion, and it calls
for complete path coverage; that is, every path (as
distinguished from independent paths) in a module must be
exercised by the test set at least once.
• This may not be a practical goal for a tester.
• For example, even in a small and simple unit of code there
may be many paths between the entry and exit nodes. Adding
even a few simple decision statements increases the number
of paths.
• Every loop multiplies the number of paths based on the
number of possible iterations of the loop since each iteration
constitutes a different path through the code. Thus, complete
path coverage for even a simple module may not be practical,
and for large and complex modules it is not feasible.
Additional White Box Test Design Approaches
Data Flow and White Box Test Design
• Some basic concepts that define the role of variables in a
software component need to be introduced.
• We say a variable is defined in a statement when its value is
assigned or changed.
For example, in the statements
Y = 26 * X
Read (Y)
Here the variable Y is defined, that is, it is assigned a new value.
In data flow notation this is indicated as a def for the variable Y.
The strongest of these criteria is all def-use paths. This includes all p-
and c-uses.
We say a path from a variable definition to a use is called a def-use
path.
To satisfy the all def-use criterion the tester must identify and classify
occurrences of all the variables in the software under test.
A tabular summary is useful.
Then for each variable, test data is generated so that all definitions
and all uses for all of the variables are exercised during test.
• The variables of interest are sum, i, n, and number.
• Since the goal is to satisfy the all def-use criteria we will need to
tabulate the def-use occurrences for each of these variables.
• The data flow role for each variable in each statement of the
example is shown beside the statement in italics.
• On the table each def-use pair is assigned an identifier.
• Line numbers are used to show occurrence of the def or use.
• Note that in some statements a given variable is both defined and
used.
The tester then generates test data to exercise all of these def-use
pairs In many cases a small set of test inputs will cover several or
all def-use paths.
For this example, two sets of test data would cover all the def-use
pairs for the variables:
Test data set 1: n = 0
Test data set 2: n = 5, number = 1,2,3,4,5
Set 1 covers pair 1 for n, pair 2 for sum, and pair 1 for i. Set 2
covers pair 1 for n, pair 1 for number, pairs 1,3,4 for sum, and
pairs 1,2,3,4 for i. Note even for this small piece of code there are
four tables and four def-use pairs for two of the variables.
• In white box testing methods, the data flow approach is most
effective at the unit level of testing. When code becomes more
complex and there are more variables to consider it becomes
more time consuming for the tester to analyze data flow roles,
identify paths, and design the tests.
• Other problems with data flow oriented testing occur in the
handling of dynamically bound variables such as pointers.
• Finally, there are no commercially available tools that provide
strong support for data flow testing, such as those that support
control-flow based testing.
Loop Testing
• Loops are among the most frequently used control structures.
Experienced software engineers realize that many defects are
associated with loop constructs. These are often due to poor
programming practices and lack of reviews. Therefore, special
attention should be paid to loops during testing.
• Beizer has classified loops into four categories:
1) simple,
2) nested,
3) concatenated,
4) unstructured.
• He advises that if instances of unstructured loops are found in
legacy code they should be redesigned to reflect structured
programming techniques.
• Testers can then focus on the remaining categories of loops.
• Loop testing strategies focus on detecting common defects
associated with these structures.
Loop Testing
example
Suppose in a simple loop that can have a range of zero to n
iterations, test cases should be developed so that there are:
a) zero iterations of the loop, i.e., the loop is skipped in its
entirely;
b) one iteration of the loop;
c) two iterations of the loop;
d) k iterations of the loop where k < n;
e) n - 1 iterations of the loop;
f) n + 1 iterations of the loop (if possible)
i = i + 1 to i = i + 2.
If we rerun the tests used for branch coverage, this mutant will
be killed, that is, the output will be different than for the
original code.
Another change we could make is in line 5, from
if a[i] > 0 to if a[i] < 0.
This mutant would also be killed by the original test data.
Therefore, we can assume that our original tests would have
caught this type of defect.