Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?

Similar presentations


Presentation on theme: "Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?"— Presentation transcript:

1 Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?

2 Structure Based Techniques Also known as ‘white-box’ or ‘glass-box’ testing technique because here the testers require knowledge of how the software is implemented Developers use structure-based techniques in component testing and component integration testing Can be used in system and acceptance testing, but the structures are different – Coverage of menu options or major business transactions

3 Structure Based Techniques Serve two purposes 1.Test coverage measurement – Used first to assess the amount of testing performed by tests derived from specification- based techniques, i.e. to assess coverage 2.Structural test case design – Used to design additional tests with the aim of increasing the test coverage.

4 Test Coverage The degree (expressed as percentage) to which a specified coverage item has been exercised by a test suite

5 Benefit of code coverage It helps in finding areas of a program not exercised by a set of test cases It creates additional test cases to increase coverage It helps in determining a quantitative measure of code coverage, which indirectly measure the quality of the application or product.

6 Disadvantage of code coverage There is danger in using a coverage measure. 100% coverage does not mean 100% tested It measures coverage of what has been written in the code; it cannot say anything about the code that has not been written If a specified function has not been implemented or a function was omitted from the specification, then structure-based techniques cannot find it

7 Test Coverage Test coverage can be used in any level of the testing – System or acceptance level, the coverage items may be requirements, menu options, screens, or typical business transactions – State transition testing: coverage measures: Percentage of states visited Percentage of (valid) transitions exercised (known as Chow’s 0- switch coverage) Percentage of pairs of valid transitions exercised (‘transition pairs’ or Chow’s 1-switch coverage) Longer series of transitions, such as transition triples, quadruples, etc. Percentage of invalid transitions exercised (from the state table)

8 Types of Test Coverage At component testing level, we have three types of test coverage – Statement coverage – Decision coverage – Condition coverage

9 Statement coverage Also known as line coverage In this process each line of code needs to be checked and executed statement coverage: The percentage of executable statements that have been exercised by a test suite

10 Statement coverage Example To achieve 100% statement coverage, one test case is required(X value is greater than Y) X = 12 and Y = 10. READ X READ Y I F X>Y THEN Z = 0 ENDIF

11 Statement coverage Example 2 The following test cases were executed, how much statement coverage did the tester achieve? – TEST SET 1 Test 1_1: X= 2, Y = 3 Test 1_2: X =0, Y = 25 Test 1_3: X =47, Y = 1 1 READ X 2 READ Y 3 Z =X + 2*Y 4 IF Z> 50 THEN 5 PRINT large Z 6 ENDIF 83% statement coverage

12 Statement coverage Advantage of statement coverage: – It checks the flow of different paths in the program and it also ensure that whether those path are tested or not. Disadvantage of statement coverage: – It cannot test the false conditions. – It does not report that whether the loop reaches its termination condition. – It does not understand the logical operators

13 Decision coverage Also known as branch coverage A decision is an IF statement, a loop control statement, or a CASE statement It covers both the true and false conditions Decision coverage: The percentage of decision outcomes that have been exercised by a test suite

14 Decision coverage Example 1 TEST SET 2: Test 2_1: A = 20, B = 15 1 READ A 2 READ B 3 C = A – 2 *B 4 IFC <0THEN 5 PRINT “C negative” 6 ENDIF

15 Decision coverage Example 1 Lets produce control flow diagram TEST SET 2 Test 2_1: A = 20, B = 15 Test 2_2: A = 10, B = 2

16 Decision coverage 100% decision coverage guarantees 100% statement coverage

17 Decision coverage Advantages of decision coverage – To validate that all the branches in the code are reached – To ensure that no branches lead to any abnormality of the program’s operation Disadvantages of decision coverage: – This metric ignores branches within boolean expressions

18 Condition coverage Condition coverage reports the true or false outcome of each conditione 1.PRINT "Hello World" 2.IF Date$ = "01-01-2000" AND Time$ = "00:00:00" THEN 3. PRINT "Happy New Year" 4.END IF 5.PRINT "The date is: "; Date$ 6.PRINT "The time is: "; Time$ 7.END

19 CONTROL FLOW TESTING The execution of a sequence of instructions from the entry point to the exit point of a program unit is called a program path A specific input value causes a specific program path to be executed; it is expected that the program path performs the desired computation, thereby producing the expected output value.

20 CONTROL FLOW GRAPH A control flow graph (CFG) is a detailed graphical representation of a program unit. Three symbols are used:

21 CONTROL FLOW GRAPH Label each computation and decision box with a unique integer Branches of a decision box are labeled with T and F Do not label a merge node

22 CONTROL FLOW GRAPH FILE *fptr1, *fptr2, *fptr3; /* These are global variables. */ int openfiles(){ /* This function tries to open files "file1", "file2", and "file3" for read access, and returns the number of files successfully opened. The file pointers of the opened files are put in the global variables. */ int i = 0; if( ((( fptr1 = fopen("file1", "r")) != NULL) && (i++) && (0)) || ((( fptr2 = fopen("file2", "r")) != NULL) && (i++) && (0)) || ((( fptr3 = fopen("file3", "r")) != NULL) && (i++)) ); return(i); }

23 Control Flow Testing Cyclomatic Complexity – A technique using mathematical graph theory to describe the complexity of a software module. – Maximum number of tests that are required to reach branch coverage – C = e – n+2p e=the number of edges in the graph (i.e., the number of arrows) n=the number of nodes (i.e., the chunks of code that are executed without loops and/or branches) p=the number of independent procedures

24 Path Testing Steps: 1: Draw a control flow graph 2: Calculate Cyclomatic complexity 3: Choose a “basis set” of paths 4: Generate test cases to exercise each path

25 Example Procedure sort do while records remain read record if record field1 =0 thenprocess record store in buffer else if record field2 =0 thenreset counter else process record end if end do end 1: 2: 3: 4: 5: 6: 7: 8: 9:

26 1, 9 1, 2,3, 8, 1, 9 1, 2, 4, 5, 7, 8, 1, 9 1, 2, 4, 6, 7, 8, 1, 9 Test cases should be derived so that all of these paths are executed Example Control Flow Graph 1 2 3 56 8 9 7 4

27 Another Example- ReturnAverage

28 CONTROL FLOW GRAPH ReturnAverage

29 Example - ReturnAverage

30 Quiz FindMean (FILE ScoreFile) { float SumOfScores = 0.0; int NumberOfScores = 0; float Mean=0.0; float Score; Read(ScoreFile, Score); while (! EOF(ScoreFile) { if (Score > 0.0 ) { SumOfScores = SumOfScores + Score; NumberOfScores++; } Read(ScoreFile, Score); } /* Compute the mean and print the result */ if (NumberOfScores > 0) { Mean = SumOfScores / NumberOfScores; printf(“ The mean score is %f\n”, Mean); } else printf (“No scores found in file\n”); } 1 2 3 4 5 7 6 8 9 Draw Control Graph for this code


Download ppt "Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?"

Similar presentations


Ads by Google