A White Box Testing

  • Published on
    06-Apr-2018

  • View
    217

  • Download
    0

Embed Size (px)

Transcript

<ul><li><p>8/3/2019 A White Box Testing</p><p> 1/3</p><p>1</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 1</p><p>White box testing</p><p>derives test cases from program code</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 2</p><p>Structural Coverage Testing</p><p>(In)adequacy criteria If significant parts of program structure are</p><p>not tested, testing is inadequate</p><p>Control flow coverage criteria</p><p> Statement coverage</p><p> Edge coverage</p><p> Condition coverage</p><p> Path coverage</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 3</p><p>Statement-coverage criterion</p><p>Select a test set T such that everyelementary statement in P is executedat least once by some d in T</p><p> an input datum executes many statements try to minimize the number of test casesstill preserving the desired coverage</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 4</p><p>Exampleread (x); read (y);if x &gt; 0 then</p><p>write ("1");else</p><p>write ("2");</p><p>end if;if y &gt; 0 then</p><p>write ("3");else</p><p>write ("4");end if;</p><p>{, ,, }covers all statements</p><p>{, }is minimal</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 5</p><p>Weakness of the criterion</p><p>if x &lt; 0 thenx := -x;</p><p>end if;z := x;</p><p>{</p></li><li><p>8/3/2019 A White Box Testing</p><p> 2/3</p><p>2</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 7</p><p>G G1 2 G1</p><p>G1</p><p>G1</p><p>G 2</p><p>I/O, assignment,or procedure call</p><p>if-then-else if-then</p><p>while loop</p><p>two sequentialstatements</p><p>Control graph construction rules</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 8</p><p>Simplification</p><p>a sequence of edges can be collapsed into just one edge</p><p>. . .</p><p>n n nnn k-1 k1 2 3</p><p>n1</p><p>nk</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 9</p><p>beginread (x); read (y);while x y loop</p><p>if x &gt; y thenx := x - y;</p><p>elsey := y - x;</p><p>end if;end loop;gcd : = x;</p><p>end;</p><p>Exemple: Euclid's algorithm</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 10</p><p>Weaknessfound := false; counter := 1;while (not found) and counter &lt; number_of_items loop</p><p>if table (counter) = desired_element thenfound := true;</p><p>end if;counter := counter + 1;</p><p>end loop;if found then</p><p>write ("the desired element is in the table");else</p><p>write ("the desired element is not in the table");</p><p>end if;</p><p>test cases: (1) empty table, (2) table with 3 items, second ofwhich is the item to look for</p><p>do not discover error (&lt; instead of )</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 11</p><p>Condition-coverage criterion</p><p>Select a test set T such that every edge ofPs control flow is traversed and allpossible values of the constituents of</p><p>compound conditions are exercised atleast once</p><p> it is finer than edge coverage</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 12</p><p>Weakness</p><p>{, }causes the execution of all edges,</p><p>but fails to expose the risk of adivision by zero</p><p>if x 0 theny := 5;</p><p>elsez := z - x;</p><p>end if;if z &gt; 1 thenz := z / x;</p><p>elsez := 0;</p><p>end if;</p></li><li><p>8/3/2019 A White Box Testing</p><p> 3/3</p><p>3</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 13</p><p>Path-coverage criterion</p><p>Select a test set T which traverses all pathsfrom the initial to the final node of Pscontrol flow</p><p> it is finer than previous kinds of coverage</p><p> however, number of paths may be too large,or even infinite (see while loops)</p><p> additional constraints must be provided</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 14</p><p>The infeasibility problem</p><p>Syntactically indicated behaviors (statements,edges, etc.) are often impossible</p><p> unreachable code, infeasible edges, paths, etc.</p><p>Adequacy criteria may be impossible to satisfy</p><p> manual justification for omitting each impossible</p><p>test case</p><p> adequacy scores based on coverage</p><p> example: 95% statement coverage</p><p>Slides adatped from those of Ghezzi, Jazayeri, and Mandrioli 15</p><p>Further problem</p><p>What if the code omits the implementation ofsome part of the specification?</p><p>White box test cases derived from the codewill ignore that part of the specification!</p></li></ul>