



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture note from the university of colorado, csci 3308 - fall semester, 2003, focusing on structural testing. It covers the concept of control flow graphs (cfgs), types of coverage such as statement, edge, condition, and relational coverage, and the importance of testing all statements, edges, and conditions. The document also discusses the challenges of achieving path coverage and the use of heuristics to approximate it.
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




October 31, 2003
© University of Colorado, 2003
Terminology Techniques Examples
October 31, 2003
© University of Colorado, 2003
3
Structural Testing supplies another criteria to answerthe question:^
“How many test cases are enough?” ^
Recall that functional testing’s criteria was “Test allfunctions” ^
Structural Testing’s criteria is “Test all code”^
Structural Testing is also known as white box testing,because now we look at a program’s source code to helpcreate test cases
October 31, 2003
© University of Colorado, 2003
^
A node in a CFG represents a program statement An edge in the CFG represents the ability for aprogram to flow from its current statement to thestatement at the other end of the edge
^
If an edge is associated with a conditional, label the edgewith the conditional’s value, either true or false
© University of Colorado, 2003
5
(^123456789101112131415)
function
P
return
INTEGER
is
begin
X, Y: INTEGER;READ(X); READ(Y); while
(X > 10)
loop
X := X – 10; exit when
X = 10;
end loop
;
if^ (Y < 20
and then
X
mod
2 = 0)
then
Y := Y + 20; else
Y := Y – 20; end if
; return
^2
∗^
X^ +
Y;
end
P;
October 31, 2003
© University of Colorado, 2003
© University of Colorado, 2003
7
Statement Coverage^ ^
Every statement is executed at least once
^
Edge Coverage^ ^
Every edge is traversed at least once
^
Condition Coverage^ ^
For binary logical operators (&&, ||), the individual components areevaluated in every possible combination of true and false
^
Relational Coverage^ ^
For relational operators (<, >, <=, >=) the equal condition is treated as aseparate branch
^
Path Coverage^ ^
Every possible path is executed at least once
October 31, 2003
© University of Colorado, 2003
© University of Colorado, 2003
13
Traverse each edge at least once Pick test case and plot its path through CFG Keep picking test cases until all edges arecovered ^
We must traverse each conditional (such as an ifstatement) along its true and false edge
October 31, 2003
© University of Colorado, 2003
© University of Colorado, 2003
15
Example all-edges-adequate test set:
(X = 20, Y = 10)
October 31, 2003
© University of Colorado, 2003
Example all-edges-adequate test set:
(X = 20, Y = 10)(X =15, Y = 30)
© University of Colorado, 2003
17
Example all-edges-adequate test set:
(X = 20, Y = 10)(X =15, Y = 30)
October 31, 2003
© University of Colorado, 2003
^
in binary logical operators (also known as shortcircuit operators), all possible combinations oftrue and false must be tested
^
© University of Colorado, 2003
19
October 31, 2003
© University of Colorado, 2003
Example all-conditions-adequate test set:
(X = 20, Y = 10)
© University of Colorado, 2003
25
^
x < y, x > y, x == y ^
October 31, 2003
© University of Colorado, 2003
Traverse each path at least once ^
Way too many paths, even in simple programs ^
Use heuristics
^
e.g. for each loop take loop zero, one, and multiple times
© University of Colorado, 2003
27
How many paths does thefollowing program fragmenthave?^ a << cin; b = 0;while (a > 0) {
a--; b++; } if (b > 5) {
printf(“b > 5”); } else {
printf(“b <= 5”); }
^
For any particular valueof a, there is only onepath possible ^
but since a is enteredby user, there are aninfinite number ofpossible paths!
October 31, 2003
© University of Colorado, 2003
In general^ ^
for loops^
traversing a loop zero, one, two, … times is each a differentpath, so a loop has a potentially infinite number of paths ^
for conditionals^
traverse true and false branches for a program consisting of only if statements
^
if x is the number of if statements, there are a total of 2
x^ paths!
^
As such, path coverage is an infeasible testingcriteria in the general case; so use heuristics toapproximate it, as discussed previously