A White Box Testing

Embed Size (px)

Text of A White Box Testing

  • 8/3/2019 A White Box Testing

    1/3

    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 everyelementary statement in P is executedat least once by some d in T

    an input datum executes many statements try to minimize the number of test casesstill preserving the desired coverage

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

    Exampleread (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;

    {, ,, }covers all statements

    {, }is minimal

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

    Weakness of the criterion

    if x < 0 thenx := -x;

    end if;z := x;

    {

  • 8/3/2019 A White Box Testing

    2/3

    2

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

    G G1 2 G1

    G1

    G1

    G 2

    I/O, assignment,or procedure call

    if-then-else if-then

    while loop

    two sequentialstatements

    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 n nnn k-1 k1 2 3

    n1

    nk

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

    beginread (x); read (y);while x y loop

    if x > y thenx := x - y;

    elsey := y - x;

    end if;end loop;gcd : = x;

    end;

    Exemple: Euclid's algorithm

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

    Weaknessfound := false; counter := 1;while (not found) and counter < number_of_items loop

    if table (counter) = desired_element thenfound := 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 ofwhich 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 ofPs control flow is traversed and allpossible values of the constituents of

    compound conditions are exercised atleast once

    it is finer than edge coverage

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

    Weakness

    {, }causes the execution of all edges,

    but fails to expose the risk of adivision by zero

    if x 0 theny := 5;

    elsez := z - x;

    end if;if z > 1 thenz := z / x;

    elsez := 0;

    end if;

  • 8/3/2019 A White Box Testing

    3/3

    3

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

    Path-coverage criterion

    Select a test set T which traverses all pathsfrom the initial to the final node of Pscontrol flow

    it is finer than previous kinds of coverage

    however, number of paths may be too large,or even infinite (see while loops)

    additional constraints must be provided

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

    The infeasibility problem

    Syntactically indicated behaviors (statements,edges, etc.) are often impossible

    unreachable code, infeasible edges, paths, etc.

    Adequacy criteria may be impossible to satisfy

    manual justification for omitting each impossible

    test case

    adequacy scores based on coverage

    example: 95% statement coverage

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

    Further problem

    What if the code omits the implementation ofsome part of the specification?

    White box test cases derived from the codewill ignore that part of the specification!