Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Software Testing (Lecture 10) 2 Organization of this Lecture zIntroduction to Testing. zWhite-box testing: ystatement coverage ypath coverage ybranch.

Similar presentations


Presentation on theme: "1 Software Testing (Lecture 10) 2 Organization of this Lecture zIntroduction to Testing. zWhite-box testing: ystatement coverage ypath coverage ybranch."— Presentation transcript:

1

2 1 Software Testing (Lecture 10)

3 2 Organization of this Lecture zIntroduction to Testing. zWhite-box testing: ystatement coverage ypath coverage ybranch testing ycondition coverage yCyclomatic complexity zSummary

4 3 How do you test a system? zInput test data to the system. zObserve the output: yCheck if the system behaved as expected.

5 4 How do you test a system?

6 5 zIf the program does not behave as expected: ynote the conditions under which it failed. ylater debug and correct.

7 6 Errors and Failures zA failure is a manifestation of an error (aka defect or bug). ymere presence of an error may not lead to a failure.

8 7 Test cases and Test suite zTest a software using a set of carefully designed test cases: yt he set of all test cases is called the test suite

9 8 Test cases and Test suite zA test case is a triplet [I,S,O]: yI is the data to be input to the system, yS is the state of the system at which the data is input, yO is the expected output from the system.

10 9 Verification versus Validation zVerification is the process of determining: ywhether output of one phase of development conforms to its previous phase. zValidation is the process of determining ywhether a fully developed system conforms to its SRS document.

11 10 Verification versus Validation zAim of Verification: yphase containment of errors zAim of validation: yfinal product is error free.

12 11 Verification versus Validation zVerification: yare we doing right? zValidation: yhave we done right?

13 12 Design of Test Cases zExhaustive testing of any non- trivial system is impractical: yinput data domain is extremely large. zDesign an optimal test suite: yof reasonable size yto uncover as many errors as possible.

14 13 Design of Test Cases zIf test cases are selected randomly: ymany test cases do not contribute to the significance of the test suite, ydo not detect errors not already detected by other test cases in the suite. zThe number of test cases in a randomly selected test suite: ynot an indication of the effectiveness of the testing.

15 14 Design of Test Cases zTesting a system using a large number of randomly selected test cases: ydoes not mean that many errors in the system will be uncovered. zConsider an example: yfinding the maximum of two integers x and y.

16 15 Design of Test Cases zIf (x>y) max = x; else max = x; zThe code has a simple error: ztest suite {(x=3,y=2);(x=2,y=3)} can detect the error, za larger test suite {(x=3,y=2);(x=4,y=3); (x=5,y=1)} does not detect the error.

17 16 Design of Test Cases zSystematic approaches are required to design an optimal test suite: yeach test case in the suite should detect different errors.

18 17 Design of Test Cases zTwo main approaches to design test cases: yBlack-box approach yWhite-box (or glass-box) approach

19 18 Black-box Testing zTest cases are designed using only functional specification of the software: ywithout any knowledge of the internal structure of the software. zFor this reason, black-box testing is also known as functional testing.

20 19 White-box Testing zDesigning white-box test cases: yrequires knowledge about the internal structure of software. ywhite-box testing is also called structural testing.

21 20 Black-box Testing zTwo main approaches to design black box test cases: yEquivalence class partitioning yBoundary value analysis

22 21 White-Box Testing zThere exist several popular white-box testing methodologies: yStatement coverage ybranch coverage ypath coverage ycondition coverage ymutation testing ydata flow-based testing

23 22 Statement Coverage zStatement coverage methodology: ydesign test cases so that xevery statement in a program is executed at least once.

24 23 Statement Coverage zThe principal idea: yunless a statement is executed, ywe have no way of knowing if an error exists in that statement.

25 24 Statement coverage criterion zBased on the observation: yan error in a program can not be discovered: xunless the part of the program containing the error is executed.

26 25 Statement coverage criterion zObserving that a statement behaves properly for one input value: yno guarantee that it will behave correctly for all input values.

27 26 Example zint f1(int x, int y){ z1 while (x != y){ z2 if (x>y) then z3 x=x-y; z4 else y=y-x; z5 } z6 return x; }

28 27 Euclid's GCD computation algorithm zBy choosing the test set {(x=3,y=3),(x=4,y=3), (x=3,y=4)} yall statements are executed at least once.

29 28 Branch Coverage zTest cases are designed such that: ydifferent branch conditions xgiven true and false values in turn.

30 29 Branch Coverage zBranch testing guarantees statement coverage: ya stronger testing compared to the statement coverage-based testing.

31 30 Stronger testing zTest cases are a superset of a weaker testing: ydiscovers at least as many errors as a weaker testing ycontains at least as many significant test cases as a weaker test.

32 31 Example zint f1(int x,int y){ z1 while (x != y){ z2 if (x>y) then z3 x=x-y; z4 else y=y-x; z5 } z6 return x; }

33 32 Example zTest cases for branch coverage can be: z{(x=3,y=3),(x=3,y=2), (x=4,y=3), (x=3,y=4)}

34 33 Condition Coverage zTest cases are designed such that: yeach component of a composite conditional expression xgiven both true and false values.

35 34 Example zConsider the conditional expression y((c1.and.c2).or.c3): zEach of c1, c2, and c3 are exercised at least once, yi.e. given true and false values.

36 35 Branch testing zBranch testing is the simplest condition testing strategy: ycompound conditions appearing in different branch statements xare given true and false values.

37 36 Branch testing zCondition testing ystronger testing than branch testing: zBranch testing ystronger than statement coverage testing.

38 37 Condition coverage zConsider a boolean expression having n components: yfor condition coverage we require 2 n test cases.

39 38 Condition coverage zCondition coverage-based testing technique: y practical only if n (the number of component conditions) is small.

40 39 Path Coverage zDesign test cases such that: yall linearly independent paths in the program are executed at least once.

41 40 Linearly independent paths zDefined in terms of ycontrol flow graph (CFG) of a program.

42 41 Path coverage-based testing zTo understand the path coverage-based testing: ywe need to learn how to draw control flow graph of a program.

43 42 Control flow graph (CFG) zA control flow graph (CFG) describes: ythe sequence in which different instructions of a program get executed. ythe way control flows through the program.

44 43 How to draw Control flow graph? zNumber all the statements of a program. zNumbered statements: yrepresent nodes of the control flow graph.

45 44 How to draw Control flow graph? zAn edge from one node to another node exists: yif execution of the statement representing the first node xcan result in transfer of control to the other node.

46 45 Example zint f1(int x,int y){ z1 while (x != y){ z2 if (x>y) then z3 x=x-y; z4 else y=y-x; z5 } z6 return x; }

47 46 Example Control Flow Graph

48 47 How to draw Control flow graph? zSequence: y1 a=5; y2 b=a*b-1; 1 2

49 48 How to draw Control flow graph? zSelection: y1 if(a>b) then y2 c=3; y3 else c=5; y4 c=c*c;

50 49 How to draw Control flow graph? zIteration: y1 while(a>b){ y2 b=b*a; y3 b=b-1;} y4 c=b+d;

51 50 Path zA path through a program: ya node and edge sequence from the starting node to a terminal node of the control flow graph. y There may be several terminal nodes for program.

52 51 Independent path zAny path through the program: yintroducing at least one new node: xthat is not included in any other independent paths.

53 52 Independent path zIzIt is straight forward: ytyto identify linearly independent paths of simple programs. zFzFor complicated programs: yiyit is not so easy to determine the number of independent paths.

54 53 McCabe's cyclomatic metric zAn upper bound: yfor the number of linearly independent paths of a program zProvides a practical way of determining: ythe maximum number of linearly independent paths in a program.

55 54 McCabe's cyclomatic metric zGiven a control flow graph G, cyclomatic complexity V(G): y V(G)= E-N+2 xN is the number of nodes in G xE is the number of edges in G

56 55 Example Control Flow Graph

57 56 Example zCyclomatic complexity = = 3.

58 57 Cyclomatic complexity zAnother way of computing cyclomatic complexity: yinspect control flow graph ydetermine number of bounded areas in the graph zV(G) = Total number of bounded areas + 1

59 58 Bounded area zAny region enclosed by a nodes and edge sequence.

60 59 Example Control Flow Graph

61 60 Example zFrom a visual examination of the CFG: ythe number of bounded areas is 2. ycyclomatic complexity = 2+1=3.

62 61 Cyclomatic complexity zMcCabe's metric provides: xa quantitative measure of testing difficulty and the ultimate reliability zIntuitively, ynumber of bounded areas increases with the number of decision nodes and loops.

63 62 Cyclomatic complexity zThe first method of computing V(G) is amenable to automation: yyou can write a program which determines the number of nodes and edges of a graph yapplies the formula to find V(G).

64 63 Cyclomatic complexity zThe cyclomatic complexity of a program provides: ya lower bound on the number of test cases to be designed yto guarantee coverage of all linearly independent paths.

65 64 Cyclomatic complexity zDefines the number of independent paths in a program. zProvides a lower bound: yfor the number of test cases for path coverage.

66 65 Cyclomatic complexity zKnowing the number of test cases required: ydoes not make it any easier to derive the test cases, yonly gives an indication of the minimum number of test cases required.

67 66 Path testing zThe tester proposes: yan initial set of test data using his experience and judgement.

68 67 Path testing zA dynamic program analyzer is used: yto indicate which parts of the program have been tested ythe output of the dynamic analysis xused to guide the tester in selecting additional test cases.

69 68 Derivation of Test Cases zLet us discuss the steps: yto derive path coverage- based test cases of a program.

70 69 Derivation of Test Cases zDraw control flow graph. zDetermine V(G). zDetermine the set of linearly independent paths. zPrepare test cases: yto force execution along each path.

71 70 Example zint f1(int x,int y){ z1 while (x != y){ z2 if (x>y) then z3 x=x-y; z4 else y=y-x; z5 } z6 return x; }

72 71 Example Control Flow Diagram

73 72 Derivation of Test Cases zNumber of independent paths: 3 y1,6 test case (x=1, y=1) y1,2,3,5,1,6 test case(x=1, y=2) y1,2,4,5,1,6 test case(x=2, y=1)

74 73 An interesting application of cyclomatic complexity zRelationship exists between: yMcCabe's metric ythe number of errors existing in the code, ythe time required to find and correct the errors.

75 74 Cyclomatic complexity zCyclomatic complexity of a program: yalso indicates the psychological complexity of a program. ydifficulty level of understanding the program.

76 75 Cyclomatic complexity zFrom maintenance perspective, ylimit cyclomatic complexity xof modules to some reasonable value. yGood software development organizations: xrestrict cyclomatic complexity of functions to a maximum of ten or so.

77 76 Summary zExhaustive testing of non- trivial systems is impractical: ywe need to design an optimal set of test cases xshould expose as many errors as possible.

78 77 Summary zIf we select test cases randomly: ymany of the selected test cases do not add to the significance of the test set.

79 78 Summary zThere are two approaches to testing: yblack-box testing and ywhite-box testing.

80 79 Summary zDesigning test cases for black box testing: ydoes not require any knowledge of how the functions have been designed and implemented. yTest cases can be designed by examining only SRS document.

81 80 Summary zWhite box testing: yrequires knowledge about internals of the software. yDesign and code is required.

82 81 Summary zWe have discussed a few white- box test strategies. yStatement coverage ybranch coverage ycondition coverage ypath coverage

83 82 Summary zA stronger testing strategy: yprovides more number of significant test cases than a weaker one. yCondition coverage is strongest among strategies we discussed.

84 83 Summary zWe discussed McCabe’s Cyclomatic complexity metric: yprovides an upper bound for linearly independent paths ycorrelates with understanding, testing, and debugging difficulty of a program.


Download ppt "1 Software Testing (Lecture 10) 2 Organization of this Lecture zIntroduction to Testing. zWhite-box testing: ystatement coverage ypath coverage ybranch."

Similar presentations


Ads by Google