White Box Testing and Software Coverage Criteria, Study notes of Software Engineering

An overview of white box testing and different software coverage criteria, including statement coverage, edge coverage, condition coverage, and path coverage. It explains how to select a test set to achieve desired coverage and discusses the weaknesses of each criterion. The document also touches upon the infeasibility problem and the importance of considering the entire specification.

Typology: Study notes

Pre 2010

Uploaded on 07/28/2009

koofers-user-do4-1
koofers-user-do4-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 1
White box testing
derives test cases from program code
Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 2
Structural Coverage Testing
(In)adequacy criteria
If significant parts of program structure are
not tested, testing is inadequate
Control flow coverage criteria
Statement coverage
Edge coverage
Condition coverage
Path coverage
Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 3
Statement-coverage criterion
Select a test set T such that every
elementary statement in P is executed
at least once by some d in T
an input datum executes many statements
Ætry to minimize the number of test cases
still preserving the desired coverage
Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 4
Example
read (x); read (y);
if x > 0 then
write ("1");
else write ("2");
end if;
if y > 0 then
write ("3");
else write ("4");
end if;
{<x = 2, y = 3>, <x = - 13, y = 51>,
<x = 97, y = 17>, <x = - 1, y = - 1>}
covers all statements
{<x = - 13, y = 51>, <x = 2, y = - 3>}
is minimal
Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 5
Weakness of the criterion
if x < 0 then
x := -x;
end if;
z := x;
{<x=-3} covers all
statements
it does not exercise the
case when x is positive
and the then branch is
not entered
Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 6
Edge-coverage criterion
Select a test set T such that every edge
(branch) of the control flow is exercised at
least once by some d in T
this requires formalizing the concept of the control graph,
and how to construct it
edges represent statements
nodes at the ends of an edge represent entry into the statement
and exit
pf3

Partial preview of the text

Download White Box Testing and Software Coverage Criteria and more Study notes Software Engineering in PDF only on Docsity!

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 1

White box testing

derives test cases from program code

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 2

Structural Coverage Testing

(In)adequacy criteria

  • If significant parts of program structure are

not tested, testing is inadequate

Control flow coverage criteria

  • Statement coverage
  • Edge coverage
  • Condition coverage
  • Path coverage

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^3)

Statement-coverage criterion

Select a test set T such that every

elementary statement in P is executed

at least once by some d in T

  • an input datum executes many statements

Æ try to minimize the number of test cases

still preserving the desired coverage

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^4)

Example

read (x); read (y); if x > 0 then write ("1"); else write ("2"); end if; if y > 0 then write ("3"); else write ("4"); end if;

{<x = 2, y = 3>, <x = - 13, y = 51>, <x = 97, y = 17>, <x = - 1, y = - 1>} covers all statements

{<x = - 13, y = 51>, <x = 2, y = - 3>} is minimal

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^5)

Weakness of the criterion

if x < 0 then x := -x; end if; z := x;

{<x=-3} covers all statements

it does not exercise the case when x is positive and the then branch is not entered

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^6)

Edge-coverage criterion

Select a test set T such that every edge

(branch) of the control flow is exercised at

least once by some d in T

this requires formalizing the concept of the control graph, and how to construct it

  • edges represent statements
  • nodes at the ends of an edge represent entry into the statement and exit

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 7

G 1 G 2 G 1

G 1

G 1 G 2

I/O, assignment, or procedure call if-then-else if-then

while loop

two sequential statements

Control graph construction rules

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 8

Simplification

a sequence of edges can be collapsed into just one edge

n 1 n 2 n nk-1 nk

n

n

k

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^9)

begin read (x); read (y); while x ≠ y loop if x > y then x := x - y; else y := y - x; end if; end loop; gcd : = x; end;

Exemple: Euclid's algorithm

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^10)

Weakness

found := false; counter := 1; while (not found) and counter < number_of_items loop if table (counter) = desired_element then found := true; end if; counter := counter + 1; end loop; if found then write ("the desired element is in the table"); else write ("the desired element is not in the table"); end if;

test cases: (1) empty table, (2) table with 3 items, second of which is the item to look for do not discover error (< instead of ≤ )

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^11)

Condition-coverage criterion

Select a test set T such that every edge of

P’s control flow is traversed and all

possible values of the constituents of

compound conditions are exercised at

least once

  • it is finer than edge coverage

Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli (^12)

Weakness

{<x = 0, z = 1>, <x = 1, z = 3>} causes the execution of all edges, but fails to expose the risk of a division by zero

if x ≠ 0 then y := 5; else z := z - x; end if; if z > 1 then z := z / x; else z := 0; end if;