Software Testing • Basic concepts • Test equivalence

  • Published on

  • View

  • Download

Embed Size (px)


<ul><li> 1. Software Testing Basic concepts Test equivalence Terminology Dimensions of testing Testing methods Black box testing White box testing1 </li></ul> <p> 2. Basic Concepts Testing involves Running actual code On selected inputs / in selected environments Then observing the behaviour of the program / system And deciding whether the behaviour is acceptable Main goal of testing: nd bugs, break software Subsidiary goal: be thorough2 3. Test Cases Test case: everything needed for one test run Test case must contain: Inputs to the software under test Expected outputs Also useful: Reason for test case What it contributes to thoroughness Successful test case: one in which the software behaves correctly Failing test case: one in which the software behaves incorrectly3 4. Successful Test Case4 5. Failing Test Case 5 6. The Testing Problem Could be [innitely] many possible test cases Impossible to test exhaustively Testing problem: select test cases that will reveal failures, if any exist6 7. Test Equivalence Say two test cases A and B are test-equivalent if we believe software will fail on A iff it will fail on B Test-equivalence should be an equivalence relation Equivalence class (EC) for test cases: set S of test cases such that if A and B are in S, A and B are test-equivalent Equivalence partition for test cases: set P of equivalence classes such that every test case is in some class S in P7 8. Equivalence Partition Select only one test case from each equivalence class Avoids unnecessary tests 8 9. Example Software: TRIANGLE Program prompts user for input User types 3 positive real numbers separated by commas e.g. 5.1, 12.0, 13 Numbers are lengths of sides of a triangle Program responds with Equilateral if there is a valid triangle with those side lengths which is equilateral Isosceles similarly Scalene similarly Not A Triangle if there is no valid triangle with those side lengths Program also says Acute if largest angle is 90 degrees9 10. Test Equivalence for TRIANGLE Probably consider (3, 3, 3) test-equivalent to (4, 4, 4) (3, 3, 3) test-equivalent to (5, 5, 5) (3, 3, 3) not test-equivalent to (3, 4, 5) Therefore: If (3, 3, 3) is a test case, (4, 4, 4) and (5, 5, 5) should not be (3, 3, 3) and (3, 4, 5) can both be test cases 10 11. Terminology: Bugs Failure: event in which program performs incorrectly e.g. printing wrong answer Fault: problem in program causing failure e.g. &lt; used instead of 0} valid; {l | l 0} invalid; {l | l not a number} invalid Build complete test cases from those setse.g. (3, 4, 5), (-1, 3, 3), (3, a, 3), (3), (3, 4, 5, 6, 7) On outputs: Identify output events, output variables, (sets of) variable valuese.g. triangle types, angle types Build test cases that generate each onee.g. (3, 3, 3), (2, 2, 3), (3, 4, 5), (2, 10, 2) 17 18. Boundary Value Analysis Find some n such that as n either increases or decreases, we go from one EC to another (e.g. valid to invalid) Identify values of n that are Close to boundary on each side On boundary (if possible) EC 1 EC 2 Generate test cases for eachn n can be integer or real; input value, output value, number of repetitions, etc. For number representing month: 0, 1, 12, 13 For TRIANGLE example: On outputs: (3, 3, 2.99), (3, 3, 3), (3, 3, 3.01), (3, 4,4.99), (3, 4, 5), (3, 4, 5.01), . . . Number of occurrences: (3, 3), (3, 3, 3), (3, 3, 3, 3), . . .18 19. Extreme Value Analysis Find an n again Choose extremely large/small values for n Generate test cases for each n can be integer or real n can be input value, output value, number of repetitions/occurrences, etc. For TRIANGLE: On inputs/outputs: (0.000004, 0.000002, 0.000003), (43728947,43928410, 54386880) On number of repetitions: () (empty test case), (3, 3, 3, 3, 3, 3, 3,3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)19 20. Syntax Testing-f put-gfilename-m filenameget filename Basic steps: Identify target language and make explicit if not already Dene syntax formally with state machine Write test cases to cover: All transitions All incomplete inputs Each change of a valid token to an invalid one For above grammar: (put -f foo), (put -g foo), (put -m foo bar), (get foo), (put -f), (get), (put -f -g), . . .20 21. White-Box Testing Also called structural testing Basic idea: if 2 test cases execute code differently, cannot be test-equivalent What criteria do we use to decide executing the code dif- while (p!=null) { ferently? if (p-&gt;n==y) { return p; } Coverage criteria p = p-&gt;next; } ... Hierarchies of coverage criteria Statement coverage Decision coverage Dataow coverage Levels of coverage21 22. Statement Coverage A test suite achieves (100%) statement coverage on code if: For every statement in the code, there is at least one test case which causes the program to execute that statement Example: consider the insurance codepremium = 500; if ((age45) &amp;&amp; (age</p>