White Box vs Black Box

  • Published on
    03-Aug-2015

  • View
    469

  • Download
    0

Embed Size (px)

DESCRIPTION

Hai ki thut kim th tiu biu.

Transcript

<p>A</p> <p>Statement coverage vs Branch coverage</p> <p>Statement coverage : tm s lng ng t nht sao cho tt c cc nt u c i qua. Node gm : nhng node iu kin, node kt qu. Branch coverage : cn c ci tn khc l Decision coverage, tm s ng t nht sao cho tt c cc cnh u c i qua. Cho nn s lng testcase ca dng ny a phn l nhiu hn dng Statement. Bi 1 1 2 3 4 5 6 7 8 if (conditionA) { c=c+1 } if(conditionB) d=d-1 else e++</p> <p>CFG(control flow graph) :biu lung iu khin Statement coverage = 2 Branch coverage = 3 Bao ph lnh s i qua tt c cc nt : + 1, 3, 5, 6, end + 1, 3, 4, 8, end + Cn nt N sao khng i qua, N ch l dng lnh th n( cui cng), b N cng c. + Cch lm th ny : Ta ang ng nt 1, ta c hai la chn, mt i qua phi, mt i qua tri. Ta thy, nu i qua phi th khng c nt no trn con ng i c, nn ta khng i. Cn bn tri th c nt s 3. S con ng t nht i qua tt c cc nt l 2 Bao ph nhnh =3 v c t nht l 3 con ng i qua tt c 1</p> <p>cc cnh, ch no c cnh l n phi i qua. ng nhin n nhiu hn bao ph lnh. Nh iu ny : bao ph nhnh l cha ca bao ph lnh, nu nh ta c 100% bao ph nhnh, th bao ph lnh cng t 100%, ngc li khng ng. Bi 2</p> <p>Bi ny ni v Bao ph lnh : bi ny c t nht mt testcase. Bi 3</p> <p>2</p> <p>Bao ph nhnh c t 100% khng ? Khng bao gi t. V thiu default, y l trng hp t bit. Bi 4 : cch v CFG . Xem cc v d sau trc khi xem v d ny</p> <p>Dng 9 c and cho nn phi tch ra lm 2 thnh 9 v 9 . 9 tng ng vi Y 10) loop 6 X := X - 10; 7 exit when X = 10; 8 end loop; 9 if (Y &lt; 20 and then X mod 2 = 0) then 10 Y := Y + 20; 11 else 12 Y := Y - 20; 13 end if; 14 return 2 * X + Y; 15 end P; Input: X=10, Y=30 Output: 50 Note: We still cover statements like we did before, but now the focus is on the edges that we hit. Ta thy n u tin i theo true trc. Edge Coverage: Test Case 2</p> <p>6</p> <p>1 function P return INTEGER 2 begin 3 X, Y: INTEGER; 4 READ(X); READ(Y); 5 while (X &gt; 10) loop 6 X := X - 10; 7 exit when X = 10; 8 end loop; 9 if (Y &lt; 20 and then X mod 2 = 0) then 10 Y := Y + 20; 11 else 12 Y := Y - 20; 13 end if; 14 return 2 * X + Y; 15 end P; Input: X=15, Y=30</p> <p>Sau mi i theo false.( ch 7-&gt;5 ; ch 9 -12) Sau hai con ng ta c hnh nh sau 1 function P return INTEGER 2 begin 3 X, Y: INTEGER; 4 READ(X); READ(Y); 5 while (X &gt; 10) loop 6 X := X - 10; 7 exit when X = 10; 8 end loop; 9 if (Y &lt; 20 and then X mod 2 = 0) then 10 Y := Y + 20; 11 else 12 Y := Y - 20; 13 end if; 14 return 2 * X + Y; 15 end P; Test Case 1: X=20, Y=10 Test Case 2: X=15, Y=30</p> <p>7</p> <p>Cn mt cnh, v tng t. Cng nh dng bao ph lnh, bi ny cng c nhiu con ng khc nhau, nhng ta ch chn ra t nht thi theo ng nh ngha. Kt hp hai phng php s cho kt qu tt hn. Bi 7 Read a; Read b; if(a&gt;=b) print a else print b Do x; if (a ==0) print Zero do nothing;</p> <p> t 100% bao ph lnh ta cn nhng con ng no</p> <p>8</p> <p>9</p> <p>Ta thy, if a==0 ta chn i theo hng no, i xung th khng ng do khng c node no khc trn ng i, trong khi i qua phi th c mt node Print 0, ging nh gia mt con ng c nhiu ngi vi mt con ng trng trn, bn i ng no, ng nhin l i ng c nhiu ngi, i ng trng coi chng. t 100% bao ph nhnh ta cn nhng con ng no</p> <p>10</p> <p>Nh l i theo true trc ri mi ti false .</p> <p>11</p> <p>Bi 8 : switch case Hy xem cch v ( sa cht : 8-11 b)</p> <p>12</p> <p>Hoc</p> <p>13</p> <p>Lu : bi ny cc bn t v s ng hn. Bi trn cha chc ng do su tp trn mng. ( bi ny c trong bi thc hnh) C bao nhiu ng t bao ph cnh 100% ? Nh l i theo ng true trc ri mi ti false. i ti chng no cc cnh u c duyt qua l ok, mc d cn nhiu na nhng ch dng li thi. Nu mun i ht theo kiu t hp, th i mt ngh, rt l nhiu trng hp. Bi 9 Cch v cho vng lp do while</p> <p>14</p> <p>Bi 10</p> <p>100% bao ph lnh : 1-2-3 . Khng c 1-3 v nu i bn phi th t 1-3 khng c node no na. 100% bao ph nhnh : 1-2-3 v 1-3 Ch cn mt testcase thi l bao ph lnh t 100% trong khi bao ph nhnh phi cn ti 2 Bi 11</p> <p>15</p> <p>100% bao ph lnh : 1-2-5 v 1-4-5 100% bao ph nhnh : 1-2-5 v 1-4-5 Tng t nhau. Bi 12</p> <p>100% bao ph nhnh : C 3 nhnh: 1-2-3-4-5 ; 1-2-4-5 ; 1-5 100% bao ph lnh : 1-2-3-4-5 . Ti 1 : nu i bn phi th khng c nt no, nu i bn tri th c nt, nn i bn tri. Ti 2 : i ti 4 th nu i bn phi th khng c nt no trong khi bn tri th c nt 3 nn i theo bn tri.</p> <p>Bi 13</p> <p>16</p> <p>Bao ph nhnh 1-2-3-6-7 1-2-5-6-7 1-4 Bao ph lnh 1-2-3-6-7 1-2-5-6-7 Bi 14</p> <p>Bao ph nhnh 1-2-3-6-9 1-2-5-6-9 1-8-9 17</p> <p>Bao ph lnh 1-2-3-6-9 1-2-5-6-9 1-8-9 Bi 15</p> <p>Bi 16. Sa li iu kin trong while P0) {x=x+1;} if (b==3) {y=0;}</p> <p>19</p> <p>B Path coverage</p> <p>Hy nhn s khc bit v bn c th t on ra c im ca dng ny. N l mt loi bao ph nhnh nhng m lit k ton b cc con ng i c th. iu ny l khng kh thi trong nhng bi ton ln v s lng test rt ln. Cho nn t s dng phng php ny. Nu c n nhnh th cn 2n test. Chng hn nh vng lp sau 20</p> <p>Khi for ( i=1-&gt;1000) th bn cn phi c 1000 test. Trong khi bao ph nhnh th ch cn 2 test ( mt l khi true v mt khi false) V d : 100 % Path Coverage</p> <p>21</p> <p>22</p> <p>Ta c tng cng 4 testcase cho trng hp bao ph path n gin nht.</p> <p>C</p> <p>Multiple Condition Decision Coverage</p> <p>L mt dng bao ph nhnh. im khc l c nhiu iu kin xen k. V d If( a&gt; || b-10 || c%2==0) . V d : if {(X or Y) and Z} then Vi dng nh trn, ta c cc test case TEST CASE1: X=TRUE, Y=TRUE, Z=TRUE TEST CASE2: X=FALSE, Y=FALSE, Z=FALSE TEST CASE3: X=FALSE, Y=FALSE, Z=TRUE TEST CASE4: X=FALSE, Y=TRUE, Z=TRUE TEST CASE5: X=FALSE, Y=TRUE, Z=FALSE TEST CASE6: X=TRUE, Y=FALSE, Z=TRUE .. Vi mt iu kin th ta gi l decision, nhng y c nhiu iu kin nh 23</p> <p>vy th ta gi kt qu sau khi tnh ton trong if l decision outcome. In test case 3 decision outcome is FALSE In test case 4 decision outcome is TRUE In test case 5 decision outcome is FALSE In test case 6 decision outcome is TRUE Nu c n iu kin th c 2 m n test. Trong lc lm nhng v d trn, cc bn gp qua dng ny ri. By gi ta ly v d n gin cht. if (a&gt;0 &amp;&amp; c==1) {x=x+1;} if (b==3 || d2F.. ( s ch T/F lin nhau gp i C6 tc l 2) +C4 : 4T -&gt; 4F -&gt; 4T -&gt; 4F. ( T/F lin nhau gp i c5 tc l 4) +C3 : 8T -&gt; 8F -&gt; 8T-&gt;8F . Dng th ny</p> <p>-</p> <p>-</p> <p>Sau , iu kin no khng cn th xa T/F i ri thay bng du nh trn. Tuy nhin, quy tc trn gy nn s d tha, mt s trng hp c ri li c lp li, cch tt nht l gom nhng trng hp ging nhau li thnh mt rule. Nh bi tam gic trn, khng theo quy tc ca chng ta. Hy cch vit ca dng bi tam gic . Xt v d sau</p> <p>36</p> <p>Chng ta thy c tng cng 2^6 = 64 Rule. Nhng n li gom nhng trng hp chung li v cui cng cn 11 Rule. Rule count ch s lng Rule trng nhau. Rule 1 c username l F, 31 rule khc cng c username l F, cng c chung kt qu l khng phi tam gic. Cch vit chng ta hay dng : i t trn xung di, (Rule1,C1 ) =F, coi li thut ton thy ch cn F l n sai ri nn tip tc i xung di v in du ngch ngang vo cho tt c 5 cn li. Tip tc n (Rule2,C1) cho = T, ng th i xung 2 v cho n = False, coi li thut ton thy F l sai ri nn 4 cn li khng quan tm ti, in vo du ngch ngang, c th tip tc hon i vai tr ca tng . Khi ti Rule 4, th c1,c2,c3 u l T nn m bo l ta c mt tam gic, by gi ch cn xc nh n l tam gic g thi. Thm mt nhn xt, Rule1,2,3 m bo nhp ng format d liu, khi nhp ng ri th ta mi tnh ti thut ton chnh ( cc rule cn li) , nn cc rule v sau s khng c du gch ngang.</p> <p>V d Cho cc iu kin v action nh di</p> <p>in T/F theo kiu n gin 37</p> <p>Nu khng thch cch n gin trn, dng cch hay hn, u tin ng no Rule1 cho name sai th khi ng nhp, cho nn b ht 2 iu kin cn li Rule2 cho name ng, nu ng th tnh ti mt khu sai, nu mt khu sai th khi ng nhp nn b k cn li. Rule 3 cho name ng, pass ng, cn ci cn li cho sai . Tip tc th t t vo l nu Rule1 l F, Rule5,6,7,8 l False cho username, nn ta gp li thnh mt trng hp chung, trng hp chung l rule1.( ni phn rule count) ch l mt s nhn xt khi nhn vo hnh, cn nhiu na, gn coi v nghin cu. Hnh di ch cn 4 Rule, gim i rt nhiu ri phi khng.</p> <p>38</p> <p>nh du cht to testcase</p> <p>To test case</p> <p>Ti liu c tng hp t nhiu ngun khc nhau. Mi vn lin quan, xin tham kho thm trn mng.</p> <p>39</p> <p>40</p>