White box testing - PDF

Document Sample
White box testing - PDF Powered By Docstoc
					                                                                                  Structural Coverage Testing
                                                                                  (In)adequacy criteria
                                                                                     – If significant parts of program structure are
White box testing                                                                      not tested, testing is inadequate
                                                                                  Control flow coverage criteria
                                                                                     – Statement coverage
   derives test cases from program code                                              – Edge coverage
                                                                                     – Condition coverage
                                                                                     – Path coverage

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




                                                                                   Example
Statement-coverage criterion                                                      read (x); read (y);
                                                                                  if x > 0 then
                                                                                                                    {<x = 2, y = 3>, <x = - 13, y = 51>,
Select a test set T such that every                                                       write ("1");
                                                                                  else                              <x = 97, y = 17>, <x = - 1, y = - 1>}
 elementary statement in P is executed                                                    write ("2");              covers all statements
 at least once by some d in T                                                     end if;
                                                                                  if y > 0 then                     {<x = - 13, y = 51>, <x = 2, y = - 3>}
  – an input datum executes many statements                                                                         is minimal
                                                                                          write ("3");
        try to minimize the number of test cases
                                                                                  else
    still preserving the desired coverage                                                 write ("4");
                                                                                  end if;


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




Weakness of the criterion                                                         Edge-coverage criterion

   if x < 0 then
                                         {<x=-3} covers all                       Select a test set T such that every edge
           x := -x;
                                         statements                                (branch) of the control flow is exercised at
   end if;
   z := x;                                                                         least once by some d in T
                                         it does not exercise the
                                         case when x is positive                    this requires formalizing the concept of the control graph,
                                         and the then branch is                     and how to construct it
                                         not entered                                 – 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   5                    Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli   6




                                                                                                                                                                      1
        Control graph construction rules
                                                                                                       Simplification
                                          G1                      G2                   G1

                                                                                                          a sequence of edges can be collapsed into just one edge
  I/O, assignment,
  or procedure call                                                                                       n1           n2                      n3                           nk-1        n
                                           if-then-else                                if-then                                                                                              k
                                                                                                                                                            ...
                                                                  G1

                                                                              two sequential
                                                                              statements                                       n1                                  n
               G1                                                                                                                                                      k
                                                                   G2

        while loop adatped from those of Ghezzi, Jazayeri, and Mandrioli
                  Slides                                                                          7                      Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli           8




        Exemple: Euclid's algorithm                                                                     Weakness
                                                                                                        found := false; counter := 1;
                                                                                                        while (not found) and counter < number_of_items loop
begin                                                                                                           if table (counter) = desired_element then
        read (x); read (y);                                                                                             found := true;
        while x ≠ y loop                                                                                        end if;
               if x > y then                                                                                    counter := counter + 1;
                       x := x - y;                                                                      end loop;
               else                                                                                     if found then
                       y := y - x;                                                                              write ("the desired element is in the table");
               end if;                                                                                  else
        end loop;                                                                                               write ("the desired element is not in the table");
        gcd : = x;                                                                                      end if;
end;
                                                                                                      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              9                      Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli           10




Condition-coverage criterion                                                                           Weakness
                                                                                                           if x ≠ 0 then
Select a test set T such that every edge of                                                                        y := 5;
 P’s control flow is traversed and all                                                                     else                              {<x = 0, z = 1>, <x = 1, z = 3>}
 possible values of the constituents of                                                                            z := z - x;               causes the execution of all edges,
                                                                                                           end if;                           but fails to expose the risk of a
 compound conditions are exercised at                                                                      if z > 1 then                     division by zero
 least once                                                                                                        z := z / x;
   – it is finer than edge coverage                                                                        else
                                                                                                                   z := 0;
                                                                                                           end if;


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




                                                                                                                                                                                                     2
Path-coverage criterion                                                           The infeasibility problem
                                                                                  Syntactically indicated behaviors (statements,
Select a test set T which traverses all paths                                       edges, etc.) are often impossible
 from the initial to the final node of P’s                                          – unreachable code, infeasible edges, paths, etc.
 control flow                                                                     Adequacy criteria may be impossible to satisfy
  – it is finer than previous kinds of coverage                                     – manual justification for omitting each impossible
                                                                                      test case
  – however, number of paths may be too large,
                                                                                    – adequacy “scores” based on coverage
    or even infinite (see while loops)                                                 • example: 95% statement coverage
     • additional constraints must be provided


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




Further problem

What if the code omits the implementation of
 some part of the specification?
White box test cases derived from the code
 will ignore that part of the specification!




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




                                                                                                                                                                   3