white box
DESCRIPTION
This ppt briefly describes software testing using the white box method.TRANSCRIPT
![Page 1: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/1.jpg)
1
Software Testing
![Page 2: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/2.jpg)
2
Organization of this Lecture
Introduction to Testing. White-box testing:
statement coverage path coverage branch testing condition coverage Cyclomatic complexity
Summary
![Page 3: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/3.jpg)
3
How do you test a system?
Input test data to the system.
Observe the output: Check if the system behaved as expected.
![Page 4: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/4.jpg)
4
How do you test a system?
![Page 5: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/5.jpg)
5
How do you test a system?If the program does not behave as expected: note the conditions under which it failed.
later debug and correct.
![Page 6: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/6.jpg)
6
Errors and FailuresA failure is a manifestation of an error (aka defect or bug). mere presence of an error may not lead to a failure.
![Page 7: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/7.jpg)
7
Test cases and Test suite
Test a software using a set of carefully designed test cases: the set of all test cases is called the test suite
![Page 8: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/8.jpg)
8
Test cases and Test suite
A test case is a triplet [I,S,O]: I is the data to be input to the system,
S is the state of the system at which the data is input,
O is the expected output from the system.
![Page 9: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/9.jpg)
9
Verification versus ValidationVerification is the process of
determining: whether output of one phase of
development conforms to its previous phase.
Validation is the process of determining whether a fully developed system
conforms to its SRS document.
![Page 10: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/10.jpg)
10
Verification versus Validation
Aim of Verification: phase containment of errors
Aim of validation: final product is error free.
![Page 11: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/11.jpg)
11
Verification versus Validation
Verification: are we doing right?
Validation: have we done right?
![Page 12: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/12.jpg)
12
Design of Test CasesExhaustive testing of any non-
trivial system is impractical: input data domain is extremely large.
Design an optimal test suite: of reasonable size to uncover as many errors as
possible.
![Page 13: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/13.jpg)
13
Design of Test CasesIf test cases are selected randomly:
many test cases do not contribute to the significance of the test suite,
do not detect errors not already detected by other test cases in the suite.
The number of test cases in a randomly selected test suite: not an indication of the effectiveness of
the testing.
![Page 14: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/14.jpg)
14
Design of Test Cases
Testing a system using a large number of randomly selected test cases: does not mean that many errors in
the system will be uncovered.Consider an example:
finding the maximum of two integers x and y.
![Page 15: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/15.jpg)
15
Design of Test Cases
If (x>y) max = x; else max = x;
The code has a simple error:test suite {(x=3,y=2);
(x=2,y=3)} can detect the error, a larger test suite {(x=3,y=2);
(x=4,y=3); (x=5,y=1)} does not detect the error.
![Page 16: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/16.jpg)
16
Design of Test Cases
Systematic approaches are required to design an optimal test suite: each test case in the suite should detect different errors.
![Page 17: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/17.jpg)
17
Design of Test CasesTwo main approaches to design test cases: Black-box approach White-box (or glass-box) approach
![Page 18: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/18.jpg)
18
Black-box TestingTest cases are designed using only
functional specification of the software: without any knowledge of the
internal structure of the software.For this reason, black-box testing
is also known as functional testing.
![Page 19: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/19.jpg)
19
White-box TestingDesigning white-box test cases: requires knowledge about the internal structure of software.
white-box testing is also called structural testing.
![Page 20: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/20.jpg)
20
Black-box Testing
Two main approaches to design black box test cases: Equivalence class partitioning
Boundary value analysis
![Page 21: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/21.jpg)
21
White-Box Testing
There exist several popular white-box testing methodologies: Statement coverage branch coverage path coverage condition coverage mutation testing data flow-based testing
![Page 22: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/22.jpg)
22
Statement CoverageStatement coverage methodology: design test cases so that
every statement in a program is executed at least once.
![Page 23: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/23.jpg)
23
Statement Coverage
The principal idea: unless a statement is executed,
we have no way of knowing if an error exists in that statement.
![Page 24: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/24.jpg)
24
Statement coverage criterion
Based on the observation: an error in a program can not be discovered: unless the part of the program containing the error is executed.
![Page 25: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/25.jpg)
25
Statement coverage criterion
Observing that a statement behaves properly for one input value: no guarantee that it will behave correctly for all input values.
![Page 26: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/26.jpg)
26
Example
int f1(int x, int y){ 1 while (x != y){2 if (x>y) then 3 x=x-y;4 else y=y-x;5 }6 return x; }
![Page 27: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/27.jpg)
27
Euclid's GCD computation algorithm
By choosing the test set {(x=3,y=3),(x=4,y=3), (x=3,y=4)} all statements are executed at least once.
![Page 28: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/28.jpg)
28
Branch Coverage
Test cases are designed such that: different branch conditionsgiven true and false values in turn.
![Page 29: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/29.jpg)
29
Branch Coverage
Branch testing guarantees statement coverage: a stronger testing compared to the statement coverage-based testing.
![Page 30: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/30.jpg)
30
Stronger testingTest cases are a superset of
a weaker testing: discovers at least as many errors as a weaker testing
contains at least as many significant test cases as a weaker test.
![Page 31: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/31.jpg)
31
Example
int f1(int x,int y){ 1 while (x != y){2 if (x>y) then 3 x=x-y;4 else y=y-x;5 }6 return x; }
![Page 32: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/32.jpg)
32
Example
Test cases for branch coverage can be:
{(x=3,y=3),(x=3,y=2), (x=4,y=3), (x=3,y=4)}
![Page 33: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/33.jpg)
33
Condition Coverage
Test cases are designed such that: each component of a composite conditional expression given both true and false values.
![Page 34: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/34.jpg)
34
Example
Consider the conditional expression ((c1.and.c2).or.c3):
Each of c1, c2, and c3 are exercised at least once, i.e. given true and false values.
![Page 35: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/35.jpg)
35
Branch testingBranch testing is the simplest condition testing strategy: compound conditions appearing in different branch statements are given true and false values.
![Page 36: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/36.jpg)
36
Branch testing
Condition testing stronger testing than branch testing:
Branch testing stronger than statement coverage testing.
![Page 37: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/37.jpg)
37
Condition coverage
Consider a boolean expression having n components: for condition coverage we require 2n test cases.
![Page 38: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/38.jpg)
38
Condition coverage
Condition coverage-based testing technique: practical only if n (the number of component conditions) is small.
![Page 39: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/39.jpg)
39
Path Coverage
Design test cases such that: all linearly independent paths in the program are executed at least once.
![Page 40: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/40.jpg)
40
Linearly independent paths
Defined in terms of control flow graph (CFG) of a program.
![Page 41: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/41.jpg)
41
Path coverage-based testing
To understand the path coverage-based testing: we need to learn how to draw control flow graph of a program.
![Page 42: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/42.jpg)
42
Control flow graph (CFG)
A control flow graph (CFG) describes: the sequence in which different instructions of a program get executed.
the way control flows through the program.
![Page 43: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/43.jpg)
43
How to draw Control flow graph?
Number all the statements of a program.
Numbered statements: represent nodes of the control flow graph.
![Page 44: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/44.jpg)
44
How to draw Control flow graph?An edge from one node to another node exists: if execution of the statement representing the first node can result in transfer of control to the other node.
![Page 45: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/45.jpg)
45
Example
int f1(int x,int y){ 1 while (x != y){2 if (x>y) then 3 x=x-y;4 else y=y-x;5 }6 return x; }
![Page 46: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/46.jpg)
46
Example Control Flow Graph
1
2
3 4
5
6
![Page 47: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/47.jpg)
47
How to draw Control flow graph?
Sequence: 1 a=5; 2 b=a*b-1;
1
2
![Page 48: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/48.jpg)
48
How to draw Control flow graph?
Selection: 1 if(a>b) then 2 c=3; 3 else c=5; 4 c=c*c;
1
2 3
4
![Page 49: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/49.jpg)
49
How to draw Control flow graph?
Iteration: 1 while(a>b){ 2 b=b*a; 3 b=b-1;} 4 c=b+d;
1
2
3
4
![Page 50: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/50.jpg)
50
PathA path through a program:
a node and edge sequence from the starting node to a terminal node of the control flow graph.
There may be several terminal nodes for program.
![Page 51: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/51.jpg)
51
Independent path
Any path through the program: introducing at least one new node:that is not included in any other independent paths.
![Page 52: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/52.jpg)
52
Independent path
It is straight forward: to identify linearly independent paths of simple programs.
For complicated programs: it is not so easy to determine the number of independent paths.
![Page 53: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/53.jpg)
53
McCabe's cyclomatic metric
An upper bound: for the number of linearly independent paths of a program
Provides a practical way of determining: the maximum number of linearly independent paths in a program.
![Page 54: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/54.jpg)
54
McCabe's cyclomatic metric
Given a control flow graph G,cyclomatic complexity V(G): V(G)= E-N+2
N is the number of nodes in GE is the number of edges in G
![Page 55: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/55.jpg)
55
Example Control Flow Graph
1
2
3 4
5
6
![Page 56: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/56.jpg)
56
Example
Cyclomatic complexity = 7-6+2 = 3.
![Page 57: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/57.jpg)
57
Cyclomatic complexity
Another way of computing cyclomatic complexity: inspect control flow graph determine number of bounded
areas in the graphV(G) = Total number of bounded
areas + 1
![Page 58: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/58.jpg)
58
Bounded area
Any region enclosed by a nodes and edge sequence.
![Page 59: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/59.jpg)
59
Example Control Flow Graph
1
2
3 4
5
6
![Page 60: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/60.jpg)
60
Example
From a visual examination of the CFG: the number of bounded areas is 2.
cyclomatic complexity = 2+1=3.
![Page 61: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/61.jpg)
61
Cyclomatic complexity
McCabe's metric provides:a quantitative measure of testing difficulty and the ultimate reliability
Intuitively, number of bounded areas increases with the number of decision nodes and loops.
![Page 62: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/62.jpg)
62
Cyclomatic complexity
The first method of computing V(G) is amenable to automation: you can write a program which determines the number of nodes and edges of a graph
applies the formula to find V(G).
![Page 63: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/63.jpg)
63
Cyclomatic complexity
The cyclomatic complexity of a program provides: a lower bound on the number of test cases to be designed
to guarantee coverage of all linearly independent paths.
![Page 64: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/64.jpg)
64
Cyclomatic complexity
Defines the number of independent paths in a program.
Provides a lower bound: for the number of test cases for path coverage.
![Page 65: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/65.jpg)
65
Cyclomatic complexity
Knowing the number of test cases required: does not make it any easier to derive the test cases,
only gives an indication of the minimum number of test cases required.
![Page 66: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/66.jpg)
66
Path testing
The tester proposes: an initial set of test data using his experience and judgement.
![Page 67: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/67.jpg)
67
Path testingA dynamic program analyzer is
used: to indicate which parts of the program have been tested
the output of the dynamic analysis used to guide the tester in selecting additional test cases.
![Page 68: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/68.jpg)
68
Derivation of Test Cases
Let us discuss the steps: to derive path coverage-based test cases of a program.
![Page 69: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/69.jpg)
69
Derivation of Test Cases
Draw control flow graph.Determine V(G).Determine the set of linearly
independent paths.Prepare test cases:
to force execution along each path.
![Page 70: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/70.jpg)
70
Exampleint f1(int x,int y){ 1 while (x != y){2 if (x>y) then 3 x=x-y;4 else y=y-x;5 }6 return x; }
![Page 71: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/71.jpg)
71
Example Control Flow Diagram
1
2
3 4
5
6
![Page 72: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/72.jpg)
72
Derivation of Test Cases
Number of independent paths: 3 1,6 test case (x=1, y=1) 1,2,3,5,1,6 test case(x=1, y=2) 1,2,4,5,1,6 test case(x=2, y=1)
![Page 73: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/73.jpg)
73
An interesting application of cyclomatic complexity
Relationship exists between: McCabe's metric the number of errors existing in the code,
the time required to find and correct the errors.
![Page 74: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/74.jpg)
74
Cyclomatic complexity
Cyclomatic complexity of a program: also indicates the psychological complexity of a program.
difficulty level of understanding the program.
![Page 75: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/75.jpg)
75
Cyclomatic complexity
From maintenance perspective, limit cyclomatic complexity
of modules to some reasonable value. Good software development organizations: restrict cyclomatic complexity of functions to a maximum of ten or so.
![Page 76: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/76.jpg)
76
Summary
Exhaustive testing of non-trivial systems is impractical: we need to design an optimal set of test cases should expose as many errors as possible.
![Page 77: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/77.jpg)
77
Summary
If we select test cases randomly: many of the selected test cases do not add to the significance of the test set.
![Page 78: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/78.jpg)
78
Summary
There are two approaches to testing: black-box testing and white-box testing.
![Page 79: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/79.jpg)
79
Summary
Designing test cases for black box testing: does not require any knowledge of how the functions have been designed and implemented.
Test cases can be designed by examining only SRS document.
![Page 80: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/80.jpg)
80
Summary
White box testing: requires knowledge about internals of the software.
Design and code is required.
![Page 81: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/81.jpg)
81
Summary
We have discussed a few white-box test strategies. Statement coverage branch coverage condition coverage path coverage
![Page 82: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/82.jpg)
82
Summary
A stronger testing strategy: provides more number of significant test cases than a weaker one.
Condition coverage is strongest among strategies we discussed.
![Page 83: White Box](https://reader036.vdocuments.site/reader036/viewer/2022062301/5695d4f41a28ab9b02a37228/html5/thumbnails/83.jpg)
83
SummaryWe discussed McCabe’s
Cyclomatic complexity metric: provides an upper bound for linearly independent paths
correlates with understanding, testing, and debugging difficulty of a program.