Unit 2
Unit 2
• PATH TESTING:
➢ The bug assumption for the path testing strategies is that something has gone wrong
with the software that makes it take a different path than intended.
➢ As an example "GOTO X" where "GOTO Y" had been intended.
➢ Structured programming languages prevent many of the bugs targeted by path
testing: as a consequence the effectiveness for
➢ path testing for these languages is reduced and for old code in COBOL, ALP,
FORTRAN and Basic, the path testing is indespensable.
1. Process Block:
2. Decisions:
3. Case Statements:
4. Junctions:
➢ A junction is a point in the program where the control flow can merge.
➢ Examples of junctions are: the target of a jump or skip instruction in ALP, a label that
is a target of GOTO.
➢ A flow graph is a pictorial representation of a program and not the program itself, just
as a topographic map.
➢ You can’t always associate the parts of a program in a unique way with flowgraph
parts because many program structures, such as if-then-else constructs, consists of
a combination of decisions, junctions, and processes.
➢ The translation from a flowgraph element to a statement and vice versa is not always
unique. (See Figure 2.8)
➢ An improper translation from flowgraph to code during coding can lead to bugs, and
improper translation during the test design lead to missing test cases and causes
undiscovered bugs.
➢ There are many paths between the entry and exit of a typical routine.
➢ Every decision doubles the number of potential paths.
➢ every loop multiplies the number of potential paths by the number of different iteration
values possible for the loop.
For X negative, the output is X + A, while for X greater than or equal to zero,
the output is X + 2A. Following prescription 2 and executing every statement,
but not every branch, would not reveal the bug in the following incorrect
version:
➢ A Static Analysis (that is, an analysis based on examining the source code or
structure) cannot determine whether a piece of code is or is not reachable. There
could be subroutine calls with parameters that are subroutine labels, or in the above
example there could be a GOTO that targeted label 100 but could never achieve a
value that would send the program to that label.
➢ Only a Dynamic Analysis (that is, an analysis based on the code's behavior while
running - which is to say, to all intents and purposes, testing) can determine whether
code is reachable or not and therefore distinguish between the ideal structure we think
we have and the actual, buggy structure.
(2.)The high probability paths are always thoroughly tested if only to demonstrate that
the system works properly.
3. Which paths to be tested? You must pick enough paths to achieve C1+C2. The
question of what is the fewest number of such paths is interesting to the designer of
test tools that help automate the path testing, but it is not crucial to the pragmatic
(practical) design of tests. It is better to make many simple paths than a few
complicated paths.
4. Path Selection Example:
▪ After you have traced a a covering path set on the master sheet and filled in the table
for every path, check the following:
• LOOPS:
Cases for a single loop:A Single loop can be covered with two cases: Looping and Not
looping. But, experience shows that many loop-related bugs are not discovered by C1+C2.
Bugs hide themselves in corners and congregate at boundaries - in the cases of loops, at
or around the minimum or maximum number of times the loop can be iterated. The
minimum number of iterations is often zero, but it need not be.
▪ Try bypassing the loop (zero iterations). If you can't, you either have a bug, or zero
is not the minimum and you have the wrong case.
▪ Could the loop-control variable be negative? Could it appear to specify a negative
number of iterations? What happens to such a value?
▪ One pass through the loop.
▪ Two passes through the loop.
▪ A typical number of iterations, unless covered by a previous test.
▪ One less than the maximum number of iterations.
▪ The maximum number of iterations.
▪ Attempt one more than the maximum number of iterations. What prevents the loop-
control variable from having this value? What will happen with this value if it is
forced?
CASE 2: Single loop, Non-zero minimum, No excluded values
▪ Try one less than the expected minimum. What happens if the loop control variable's
value is less than the minimum? What prevents the value from being less than the
minimum?
▪ The minimum number of iterations.
▪ One more than the minimum number of iterations.
▪ Once, unless covered by a previous test.
▪ Twice, unless covered by a previous test.
▪ A typical value.
▪ One less than the maximum value.
▪ The maximum number of iterations.
▪ Attempt one more than the maximum number of iterations.
▪ Treat single loops with excluded values as two sets of tests consisting of loops
without excluded values, such as case 1 and 2 above.
▪ Example, the total range of the loop control variable was 1 to 20, but that values
7,8,9,10 were excluded. The two sets of tests are 1-6 and 11-20.
▪ The test cases to attempt would be 0,1,2,4,6,7 for the first range and
10,11,15,19,20,21 for the second range.
Kinds of Loops:There are only three kinds of loops with respect to path testing:
1. Nested Loops:
1. The number of tests to be performed on nested loops will be the exponent of the
tests performed on single loops.
2. As we cannot always afford to test all combinations of nested loops' iterations
values. Here's a tactic used to discard some of these values:
1. Start at the inner most loop. Set all the outer loops to their minimum values.
2. Test the minimum, minimum+1, typical, maximum-1 , and maximum for the
innermost loop, while holding the outer loops at their minimum iteration parameter
values. Expand the tests as required for out of range and excluded values.
3. If you've done the outmost loop, GOTO step 5, else move out one loop and set it up
as in step 2 with all other loops set to typical values.
4. Continue outward in this manner until all loops have been covered.
5. Do all the cases for all loops in the nest simultaneously.
2. Concatenated Loops:
1. Concatenated loops fall between single and nested loops with respect to test cases.
Two loops are concatenated if it's possible to reach one after exiting the other while
still on a path from entrance to exit.
2. If the loops cannot be on the same path, then they are not concatenated and can
be treated as individual loops.
3. Horrible Loops:
1. A horrible loop is a combination of nested loops, the use of code that jumps into
and out of loops, intersecting loops, hidden loops, and cross connected loops.
2. Makes iteration value selection for test cases an awesome and ugly task, which is
another reason such structures should be avoided.
Figure 2.10: Example of Loop types
Loop Testing Time :
▪ Any kind of loop can lead to long testing time, especially if all the extreme value
cases are to attempted (Max-1, Max, Max+1).
▪ This situation is obviously worse for nested and dependent concatenated loops.
▪ Consider nested loops in which testing the combination of extreme values lead to
long test times. Several options to deal with:
1. Prove that the combined extreme cases are hypothetically possible, they are not
possible in the real world
2. Put in limits or checks that prevent the combined extreme cases. Then you have
to test the software that implements such safety measures.
▪ The path taken through a multiway branch such as a computed GOTO's, case
statement, or jump tables cannot be directly expressed in TRUE/FALSE terms.
▪ Although, it is possible to describe such alternatives by using multi valued logic, an
expedient (practical approach) is to express multiway branches as an equivalent
set of if..then..else statements.
▪ For example a three way case statement can be written as: If case=1 DO A1 ELSE
(IF Case=2 DO A2 ELSE DO A3 ENDIF)ENDIF.
INPUTS:
▪ In testing, the word input is not restricted to direct inputs, but includes all data
objects referenced by the routine whose values are fixed prior to entering it.
▪ Example:--
▪ inputs in a calling sequence,
▪ objects in a data structure,
▪ values left in registers, or
▪ any combination of object types.
▪ The input for a particular test is mapped as a one-dimensional array called as an
Input Vector.
PREDICATE INTERPRETATION:
The path predicates are the specific form of the predicates of the decisions along the
selected path after interpretation.
• The path predicates take on truth values based on the values of input variables, either
directly or indirectly.
• If a variable's value does not change as a result of processing, that variable is
independent of the processing.
• If the variable's value can change as a result of the processing, the variable is process
dependent.
• A predicate whose truth value can change as a result of the processing is said to
be process dependent and one whose truth value does not change as a result of the
processing is process independent.
• Process dependence of a predicate does not always follow from dependence of the
input variables on which that predicate is based.
• Every path through a routine is achievable only if all the predicates in that routine are
uncorrelated.
Example:
X1+3X2+17>=0
X3=17
X4-X1>=14X2
Any set of input values that satisfy all of the conditions of the path predicate expression will
force the routine to the path.
Example:
A: X5 > 0 E: X6 < 0
B: X1 + 3X2 + 17 >= 0 B: X1 + 3X2 + 17 >= 0
C: X3 = 17 C: X3 = 17
D: X4 - X1 >= 14X2 D: X4 - X1 >= 14X2
ABCD+EBCD=(A+E)BCD
Some times even a simple predicate becomes compound after interpretation. Example:
the predicate if (x=17) whose opposite branch is if x.NE.17 which is equivalent to x>17 .
Or. X<17.
PREDICATE COVERAGE:
• Predicate coverage is being the achieving of all possible combinations of truth values
corresponding to the selected path have been explored under some test.
As achieving the desired direction at a given decision could still hide bugs in the associated
predicates.
TESTING BLINDNESS:
Testing Blindness is a pathological (harmful) situation in which the desired path is achieved
for the wrong reason.
1.Assignment Blindness
2.Equality Blindness
3.Self Blindness
1.Assignment Blindness:
• Assignment blindness occurs when the buggy predicate appears to work correctly
because the specific value chosen for an assignment statement works with both the
correct and incorrect predicate.
• For Example:
• Correct • Buggy
• X=7 • X=7
........ ........
if Y > 0 then ... if X+Y > 0 then ...
• If the test case sets Y=1 the desired path is taken in either case, but there is still a
bug.
2.Equality Blindness:
• Equality blindness occurs when the path selected by a prior predicate results in a
value that works both for the correct and buggy predicate.
• For Example:
Correct Buggy
if Y = 2 then if Y = 2 then
........ ........
if X+Y > 3 then ... if X > 1 then ...
• The first predicate if y=2 forces the rest of the path, so that for any positive value of
x. the path taken at the second predicate will be the same for the correct and buggy
version.
3.Self Blindness:
• Self blindness occurs when the buggy predicate is a multiple of the correct predicate
and as a result is indistinguishable along that path.
• For Example:
Correct Buggy
X = A X = A
........ ........
if X-1 > 0 then ... if X+A-2 > 0 then ...
• The assignment (x=a) makes the predicates multiples of each other, so the direction
taken is the same for the correct and buggy version.
PATH SENSITIZING:
o REVIEW: ACHIEVABLE AND UNACHIEVABLE PATHS:
1. We want to select and test enough paths to achieve a satisfactory notion of test
completeness such as C1+C2.
2. Extract the programs control flowgraph and select a set of tentative covering paths.
3. For any path in that set, interpret the predicates along the path as needed to express
them in terms of the input vector. In general individual predicates are compound or
may become compound as a result of interpretation.
4. Trace the path through, multiplying the individual compound predicates to achieve
a boolean expression such as
ADFGHIJKL+AEFGHIJKL+BCDFGHIJKL+BCEFGHIJKL
6. Each product term denotes a set of inequalities that if solved will yield an input vector
that will drive the routine along the designated path.
7. Solve any one of the inequality sets for the chosen path and you have found a set
of input values for the path.
8. If you can find a solution, then the path is achievable.
9. If you cant find a solution to any of the sets of inequalities, the path is un achievable.
10. The act of finding a set of solutions to the path predicate expression is called PATH
SENSITIZATION.
PATH INSTRUMENTATION:
Path instrumentation is what we have to do to confirm that the outcome was
achieved by the intended path.
1. An interpretive trace program is one that executes every statement in order and
records the intermediate values of all calculations, the statement labels traversed
etc.
2. If we run the tested routine under a trace, then we have all the information we need
to confirm the outcome and, furthermore, to confirm that it was achieved by the
intended path.
3. The trouble with traces is that they give us far more information than we need. In
fact, the typical trace program provides so much information that confirming the path
from its massive output dump is more work than simulating the computer by hand
to confirm the path.
3.Link Counter
USAGE:
• Transaction flows are indispensable for specifying requirements of
complicated systems, especially online systems.
• A big system such as an air traffic control or airline reservation system, has not
hundreds, but thousands of different transaction flows.
• The flows are represented by relatively simple flowgraphs, many of which
have a single straight-through path.
• Loops are infrequent compared to control flowgraphs.
• The most common loop is used to request a retry after user input errors. An
ATM system, for example, allows the user to try, say three times, and will take
the card away the fourth time.
• COMPLICATIONS:
• In simple cases, the transactions have a unique identity from the time they'r
created to the time they're completed.
• In many systems the transactions can give birth to others, and transactions can
also merge.
• Births: There are three different possible interpretations of the decision symbol, or
nodes with two or more out links. It can be a Decision, Biosis or a Mitosis.
1. Decision: Here the transaction will take one alternative or the other
alternative but not both. (See Figure 2.3 (a))
2. Biosis: Here the incoming transaction gives birth to a new transaction, and
both transaction continue on their separate paths, and the parent retains it
identity. (See Figure 2.3 (b))
3. Mitosis: Here the parent transaction is destroyed and two new transactions
We have no problem with ordinary decisions and junctions. Births, absorptions, and
conjugations are as problematic for the software designer as they are for the software
modeler and the test designer; as a consequence, such points have more than their share
of bugs.
The common problems are: lost daughters, wrongful deaths, and illegitimate births.
• PATH SELECTION:
o Select a set of covering paths (c1+c2) using the analogous criteria you used for
structural path testing.
o Select a covering set of paths based on functionally sensible transactions as you
would for control flow graphs.
o Try to find the most tortuous, longest, strangest path from the entry to the exit of
the transaction flow.
• PATH SENSITIZATION:
o Most of the normal paths are very easy to sensitize-80% - 95% transaction flow
coverage (c1+c2) is usually easy to achieve.
o The remaining small percentage is often very difficult.
o Sensitization is the act of defining the transaction. If there are sensitization
problems on the easy paths, then bet on either a bug in transaction flows or a
design bug.
• PATH INSTRUMENTATION:
o Instrumentation plays a bigger role in transaction flow testing than in unit path
testing.
o The information of the path taken for a given transaction must be kept with that
transaction and can be recorded by a central transaction dispatcher or by the
individual processing modules.
o In some systems, such traces are provided by the operating systems or a running
log