structural testing
play

Structural Testing (c) 2007 Mauro Pezz & Michal Young Ch 12, - PowerPoint PPT Presentation

Structural Testing (c) 2007 Mauro Pezz & Michal Young Ch 12, slide 1 Learning objectives Learning objectives Understand rationale for structural testing Understand rationale for structural testing How structural (code-based


  1. Structural Testing (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 1

  2. Learning objectives Learning objectives • Understand rationale for structural testing • Understand rationale for structural testing – How structural (code-based or glass-box) testing complements functional (black-box) testing complements functional (black-box) testing • Recognize and distinguish basic terms – Adequacy, coverage Ad • Recognize and distinguish characteristics of common structural criteria l i i • Understand practical uses and limitations of structural testing (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 2

  3. “ Structural ” testing Structural testing • Judging test suite thoroughness based on the • Judging test suite thoroughness based on the structure of the program itself Also known as “ white box ” “ glass box ” or “ code – Also known as white-box , glass-box , or code- based ” testing – To distinguish from functional (requirements-based – To distinguish from functional (requirements-based, “ black-box ” testing) – “ S tructural ” testing is still testing product functionality against its specification. Only the measure of thoroughness has changed. (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 3

  4. Why structural (code-based) testing? Why structural (code-based) testing? • One way of answering the question “ What is • One way of answering the question What is ” missing in our test suite? – If part of a program is not executed by any test case If part of a program is not executed by any test case in the suite, faults in that part cannot be exposed – But what ’ s a “ part ” ? • Typically, a control flow element or combination: • S tatements (or CFG nodes), Branches (or CFG edges) • Fragments and combinations: Conditions paths • Fragments and combinations: Conditions, paths • Complements functional testing: Another way to recognize cases that are treated differently to recognize cases that are treated differently – Recall fundamental rationale: Prefer test cases that are treated differently over cases treated the same (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 4

  5. No guarantees No guarantees • Executing all control flow elements does not • Executing all control flow elements does not guarantee finding all faults – Execution of a faulty statement may not always Execution of a faulty statement may not always result in a failure • The state may not be corrupted when the statement is The state may not be corrupted when the statement is executed with some data values • Corrupt state may not propagate through execution to eventually lead to failure t ll l d t f il • What is the value of structural coverage? – Increases confidence in thoroughness of testing • Removes some obvious inadequacies (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 5

  6. Structural testing complements functional testing • Control flow testing includes cases that may not • Control flow testing includes cases that may not be identified from specifications alone – Typical case: implementation of a single item of the Typical case: implementation of a single item of the specification by multiple parts of the program – Example: hash table collision (invisible in interface – Example: hash table collision (invisible in interface spec) • Test suites that satisfy control flow adequacy • Test suites that satisfy control flow adequacy criteria could fail in revealing faults that can be caught with functional criteria caught with functional criteria – Typical case: missing path faults (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 6

  7. Structural testing in practice Structural testing in practice • Create functional test suite first, then measure Create functional test suite first, then measure structural coverage to identify see what is missing • Interpret unexecuted elements – may be due to natural differences between specification and may be due to natural differences between specification and implementation – or may reveal flaws of the software or its development process • inadequacy of specifications that do not include cases present in • inadequacy of specifications that do not include cases present in the implementation • coding practice that radically diverges from the specification • inadequate functional test suites inadequate functional test suites • Attractive because automated – coverage measurements are convenient progress indicators coverage measurements are convenient progress indicators – sometimes used as a criterion of completion • use with caution: does not ensure effective test suites (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 7

  8. Statement testing Statement testing • Adequacy criterion: each statement (or node in • Adequacy criterion: each statement (or node in the CFG) must be executed at least once • Coverage: C # executed statements # statements • Rationale: a fault in a statement can only be Rationale: a fault in a statement can only be revealed by executing the faulty statement (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 8

  9. Statements or blocks? Statements or blocks? • Nodes in a control flow graph often represent • Nodes in a control flow graph often represent basic blocks of multiple statements ome standards refer to basic block coverage or ome standards refer to basic block coverage or – S S node coverage – Difference in granularity not in concept – Difference in granularity, not in concept • No essential difference – 100% 100% node coverage <-> 100% d 100% t t statement coverage t • but levels will differ below 100% – A test case that improves one will improve the other A test case that improves one will improve the other • though not by the same amount, in general (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 9

  10. int cgi _decode (char *encoded , char *decoded ) Example A { {char *eptr = encoded ; p ; char *dptr = decoded ; int ok = 0; T 0 = B { “” , “ test ” , while (*eptr) { { , test , False True “ test+case% 1Dadequacy ” } char c; C 17/ 18 = 94% S tmt Cov . c = *eptr; if (c == '+') { False False True T T 1 = D E *dptr = ' '; elseif (c == '%') { { “ adequate+test% 0Dexecuti } 7U ” } on% False True 18/ 18 = 100% S tmt Cov . G F else int digit _high = Hex_Values [*(++eptr)]; *dptr = *eptr; int digit _low = Hex_Values [*(++eptr)]; } if (digit_high == -1 || digit_low == -1) { T 2 = False True { “ % { “ % 3 ” “ % 3D ” , “ % A ” “ A ” , “ a+b ” , b ” H I else { ok = 1; “ test ” } *dptr = 16 * digit_high + } digit_low; 18/ 18 = 100% S tmt Cov . } M ++dptr; L *dptr = '\0'; ++eptr; return ok ; } } (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 10

  11. Coverage is not size Coverage is not size • Coverage does not depend on the number of • Coverage does not depend on the number of test cases – T 0 , T 1 : T 1 > coverage T 0 T T : T > T T < T 1 < cardinality T 0 T – T 1 , T 2 : T 2 = coverage T 1 T 2 > cardinality T 1 • Minimizing test suite size is seldom the goal – small test cases make failure diagnosis easier – a failing test case in T 2 gives more information for fault localization than a failing test case in T 1 (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 11

  12. “ All statements ” can miss some cases int cgi _decode (char *encoded , char *decoded ) • Complete statement {char *eptr = encoded ; A coverage may not imply char *dptr = decoded ; int ok = 0; executing all branches in a program while (*eptr ) { B True • Example: False char c; h C – S uppose block F were c = *eptr; if (c == '+') { missing False True – S tatement adequacy elseif (c == '%') { D *dptr = ' '; E } } would not require false False True branch from D to L G else { F int digit_high = Hex_Values [*(++eptr)]; *dptr = *eptr; int digit_low = Hex_Values [*(++eptr)]; T 3 = } if (digit_high == -1 || digit_low == -1) { { “” “ % { “” , “ +% 4J ” } 4J ” } 0D % 0D+% True False 100% S tmt Cov . ok = 1; else { H I } No false branch from D *dptr = 16 * digit_high + digit_low; } } L ++dptr; *dptr = '\0'; M ++eptr; return ok ; } } } } (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 12

  13. Branch testing Branch testing • Adequacy criterion: each branch (edge in the • Adequacy criterion: each branch (edge in the CFG) must be executed at least once • Coverage: • Coverage: # executed branches # branches # branches T = { “” “ +% 4J ” } T 3 = { , +% 0D+% 0D+% 4J } 100% S tmt Cov. 88% Branch Cov. (7/ 8 branches) T 2 = { “ % 3D ” , “ % A ” , “ a+b ” , “ test ” } 100% 100% S S tmt Cov. 100% tmt Cov. 100% Branch Cov. (8/ 8 branches) Branch Cov. (8/ 8 branches) (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 13

Recommend


More recommend