Download presentation
Presentation is loading. Please wait.
1
CHAPTER 4 Test Design Techniques
The University of Lahore A “W4” Category University Lecture 31 CHAPTER 4 Test Design Techniques 20/09/2018
2
The University of Lahore
A “W4” Category University Black-Box technique is sub-divided into four techniques. 20/09/2018
3
The University of Lahore
A “W4” Category University Use Case Testing A black-box test design technique in which test cases are designed to execute user scenarios. A use case is a description of a particular use of the system by an actor (a user of a system). Each use case describes the interactions the actor has with the system in order to achieve a specific tasks. Use case are a sequence of steps that describe the interactions between the actor and the system. Use case are defined in terms of the actor, not the system, describing what the actor does and what the actor sees rather than what inputs the system expects and what the system outputs. 20/09/2018
4
The University of Lahore
A “W4” Category University 20/09/2018
5
The University of Lahore
A “W4” Category University 20/09/2018
6
The University of Lahore
A “W4” Category University 20/09/2018
7
The University of Lahore
A “W4” Category University 20/09/2018
8
The University of Lahore
A “W4” Category University 20/09/2018
9
The University of Lahore
A “W4” Category University Experienced-Based Testing techniques Error Guessing “A test design technique where the experience of the tester is used to anticipate where defects might be present in the component or system.” Success of error guessing is very much dependent on the skills of the testers. Experience testers know where the defects are most likely to be occurred. 20/09/2018
10
The University of Lahore
A “W4” Category University Exploratory Testing It is about exploring, finding out about the software, what it does, what it doesn’t do, what work and what doesn’t work. Testers are constantly making decisions about what to test next and where to spend a limited time. 20/09/2018
11
The University of Lahore
A “W4” Category University 20/09/2018
12
Definition of White-Box Testing
The University of Lahore A “W4” Category University Definition of White-Box Testing Testing based on analysis of internal logic (design, code, etc.). (But expected results still come from requirements.) Also know as structural testing. White-box testing concerns techniques for designing tests; it is not a level of testing. White-box testing techniques apply primarily to lower levels of testing (e.g., unit and component). 20/09/2018
13
The University of Lahore
A “W4” Category University Structure-Based/White-Box/Glass-Box Testing Design Techniques “A procedure to select test cases based on an analysis of the internal structure of a component or system” 20/09/2018
14
Code Coverage The University of Lahore
A “W4” Category University Code Coverage “An analysis method that determines which parts of the software have been executed (covered) and which parts have not been executed.” 20/09/2018
15
The University of Lahore
A “W4” Category University Types of Coverage Statement Coverage Decision Coverage 20/09/2018
16
The University of Lahore
A “W4” Category University The statement coverage is also known as line coverage or segment coverage. The statement coverage covers only the true conditions. Through statement coverage we can identify the statements executed and where the code is not executed. Check if each statement in the code has been executed at least once. 20/09/2018
17
The University of Lahore
A “W4” Category University Statement Coverage requires that each statement will have been executed at least once. Simplest form of logic coverage. Also known as Node Coverage. 20/09/2018
18
Statement Coverage OR Statement Testing
The University of Lahore A “W4Category University Statement Coverage OR Statement Testing “The percentage of executable statements that has been exercised.” Number of statements exercised Statement Coverage = X 100 Total number of statements 20/09/2018
19
The University of Lahore
A “W4” Category University Example 1.1 READ A READ B C = A + 2 * B IF C>50 THEN PRINT “LARGE C” ENDIF 2 READ statements 1 Assignment statement 1 If statement on three lines TEST SET 1 Test 1_1: A = 2, B = 3 Test 1_2: A = 0, B = 25 Test 1_3: A = 47, B = 1 Test 1_4: A = 20, B = 25 (100% statement coverage) 83% statement coverage 20/09/2018
20
The University of Lahore
A “W4” Category University If all statements in a program have been executed by a set of tests then 100% statement coverage has been achieved. If only half of the statement have been executed by a set of tests then 50% statement coverage has been achieved. 20/09/2018
21
The University of Lahore
A “W4” Category University Example 1.2 READ X READ Y I F X>Y THEN Z = 0 ENDIF To achieve 100% statement coverage of this code segment just 1 test case is required, one which ensures that variable X contains a value that is greater than the value of variable Y. Test Case_01: X = 12 and Y = 10. Note that here we are doing structural test design first, since we are choosing our input values in order ensure statement coverage. 20/09/2018
22
Exercise 1.3 The University of Lahore
A “W4” Category University Exercise 1.3 How many tests are required to achieve 100% statement coverage? 1 test would be required to execute all three executable statements. If our component consists of three lines of code we will execute all with one test case, thus achieving 100% statement coverage. There is only one way we can execute the code - starting at line number 1 and finishing at line number 3. 20/09/2018
23
Exercise 1.4 The University of Lahore
A “W4” Category University Exercise 1.4 How many tests are required to achieve 100% statement coverage? 20/09/2018
24
Exercise 1.5 The University of Lahore
A “W4” Category University Exercise 1.5 How many tests are required to achieve 100% statement coverage? Therefore we will need three tests that answer 'yes' to 'if fuel tank empty‘ * Fuel tank empty AND petrol engine ( to execute line 3) * Fuel tank empty AND NOT petrol engine( to execute line 5) one further test will be required where we answer 'no' to 'if fuel tank empty' to enable us to execute the statement at line 8. 20/09/2018
25
20/09/2018
26
The University of Lahore
A “W4” Category University Exercise 1.6 How many tests are required to achieve 100% statement coverage? In this example we have two separate questions that are being asked. The tests have shown are * A coffee drinker who wants cream * A non coffee drinker who doesn`t want cream Our 2 tests achieve 100% statement coverage, but equally we could have had 2 tests with: * A coffee drinker who doesn`t want cream * A no-coffee drinker who wants cream If we were being asked to achieve 100% statement coverage, and if all statements were of equal importance, it would not matter which set of tests we choose. 20/09/2018
27
The University of Lahore
A “W4” Category University Exercise 1.7 Draw flow diagram for this code: READ P, Q IF P+Q > 100 THEN PRINT 'LARGE' END IF IF P>50 PRINT 'P Is Greater' END IF 20/09/2018
28
The University of Lahore
A “W4” Category University Statement Coverage Test case_01: P=60, Q=50 20/09/2018
29
The University of Lahore
A “W4” Category University Exercise 1.8 if (x < y) { y = 0; x = x + 1; } else x = y; 4 1 2 3 x >= y x < y x = y y = 0 x = x + 1 Statement coverage: Cover every reachable statement 20/09/2018
30
The University of Lahore
A “W4” Category University Exercise 1.9 areTheyPositive(int x, int y) { if (x >= 0) print(“x is positive”); else print(“x is negative”); if (y >= 0) print(“y is positive”); print(“y is negative”); } There are smaller test cases which will give us statement coverage too: T2 = {(x=12,y= 5), (x= 1,y=35)} 20/09/2018
31
The University of Lahore
A “W4” Category University Exercise 1.10 assignAbsolute(int x) { if (x < 0) x := -x; z := x; } Consider this program segment, the test set T = {x=1} will give statement coverage, however not branch coverage B0 (x < 0) Control Flow Graph: true false B1 Test set {x=1} does not execute this edge, hence, it does not give branch coverage x := -x B2 z := x 20/09/2018
32
20/09/2018
33
The University of Lahore
A “W4” Category University 20/09/2018
34
The University of Lahore
A “W4” Category University Decision Coverage OR Condition Coverage Check if each possible branch from a decision point has been executed at least once. Condition Coverage requires that each condition will have been True at least once and False at least once. 20/09/2018
35
The University of Lahore
A “W4” Category University Decision Coverage OR Condition Coverage “The percentage if the decision outcomes that have been exercised. 100% decision coverage implies both 100% branch coverage and 100% statement coverage.” 20/09/2018
36
The University of Lahore
A “W4” Category University The objective of decision coverage testing is to show all the decisions within a component have been executed at least once. A decision can be described as a line of source code that asks a question. 100% decision coverage guarantees 100% statement coverage, but not vice versa. 20/09/2018
37
The University of Lahore
A “W4” Category University Exercise 1.1 B0 (x < 0) true false B1 Test set {x=1} does not execute this edge, hence, it does not give branch coverage Test set {x= 1, x=2} gives both statement and branch coverage x := -x B2 z := x 20/09/2018
38
The University of Lahore
A “W4” Category University Exercise 1.2 B0 (x < y) if (x < y) { x = 5 * y; x = x + 3; } else y = 5; x = x+y; Y N x = 5 * y x = x + 3 B1 y = 5 B2 x = x+y B3 20/09/2018
39
The University of Lahore
A “W4” Category University Exercise 1.3 READ A READ B C = A - 2 * B IF C<0 THEN PRINT “C negative” ENDIF TEST SET 2 Test 2_1: A = 20, B = 15 Test 2_2: A = 10, B = 2 20/09/2018
40
Exercise 1.4 The University of Lahore
A “W4” Category University Exercise 1.4 How many tests are required to achieve 100% decision coverage? 20/09/2018
41
The University of Lahore
A “W4” Category University SOLUTION In this example there is one decision, and therefore 2 outcomes. To achieve 100% decision coverage we could have two tests: 1- Age less than 17(answer 'yes') 2- Age equal to or greater than 17 (answer 'no') 1 for statement coverage 2 for decision coverage 20/09/2018
42
Exercise 1.5 The University of Lahore
A “W4” Category University Exercise 1.5 How many tests are required to achieve 100% decision coverage? 20/09/2018
43
Exercise 1.6 The University of Lahore
A “W4” Category University Exercise 1.6 How many tests are required to achieve 100% decision coverage? 20/09/2018
44
The University of Lahore
A “W4” Category University SOLUTION 1 test for statement coverage 3 tests for decision coverage SO you may think that 4 tests may be required to achieve 100% decision coverage ( two for each decision). This is NOT the case! We can achieve 100% decision coverage with three tests - we need to exercise the 'Yes' outcome from the first decision ( line 1) twice, in order to next exercise the 'Yes' and then the 'No' outcome from the supplementary question(line 2). We need a further third test to ensure we exercise the 'No' outcome of the first decision( line 1 ). There is only one decision outcome that has an associated statement - this means that 100% statement coverage can be achieved with one test. 20/09/2018
45
Exercise 1.7 The University of Lahore
A “W4” Category University Exercise 1.7 How many tests are required to achieve 100% decision coverage? 20/09/2018
46
The University of Lahore
A “W4” Category University SOLUTION 2 tests for statement coverage 3 tests for decision coverage We have now introduced a statement that is associated with 'No' outcome of the decision on line 2. This change affects the number of tests required to achieve 100% statement coverage, but does NOT alter the number of tests required to achieved 100% decision coverage - it is still three! 20/09/2018
47
Exercise 1.8 The University of Lahore
A “W4” Category University Exercise 1.8 How many tests are required to achieve 100% decision coverage? 20/09/2018
48
The University of Lahore
A “W4” Category University SOLUTION 3 tests for statement coverage 3 tests for decision coverage 20/09/2018
49
Exercise 1.9 The University of Lahore
A “W4” Category University Exercise 1.9 How many tests are required to achieve 100% statement coverage? How many tests are required to achieve 100% decision coverage? Initial value of A = 15 20/09/2018
50
The University of Lahore
A “W4” Category University SOLUTION 1 test for statement coverage 2 test for decision coverage 20/09/2018
51
The University of Lahore
A “W4” Category University Exercise 1.10 Read P Read Q IF P+Q > 100 THEN Print “Large” ENDIF If P > 50 THEN Print “P Large” 20/09/2018
52
The University of Lahore
A “W4” Category University Path Coverage 1A-2B-E-4F 1A-2B-E-4G-5H 1A-2C-3D-E-4G-5H 1A-2C-3D-E-4F 20/09/2018
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.