Professional Documents
Culture Documents
Slide Topic4 2
Slide Topic4 2
SOFTWARE TESTING
ĐẠI HỌC FPT CẦN THƠ
Software Testing Chapter 4
Foundation Of Software Testing
4 Test design
5 Management 6 Tools
techniques
1
• The test development process
2
• Categories of test design techniques
3
• Black and White box testing
4
• Black box test techniques
5
• White box test techniques
6
• Experience-based techniques
7
• Choosing a test technique
Benefits:
Testers can identify defects that cannot be detected through other
testing techniques.
Testers can create more comprehensive and effective test cases that
cover all code paths.
Testers can ensure that the code meets coding standards and is
optimized for performance.
Disadvantages:
Complexity.
Not Suitable for Large Applications.
Limited Comprehensive Testing.
Introduction
Common approaches
Statement coverage :
Each statement executed at least once
Branch/Decision coverage :
Each branch traversed (and every entry point taken) at least
once
Condition coverage:
Each condition True at least once and False at least once
Control-flow-based Testing
8
Control Flow Graphs (CFGs)
x = x+y B3
• Each block has a sequence of statements
• No jump from or to the middle of the block
• Once a block starts executing, it will execute till the end
Example of a Control Flow Graph (CFG)
s:=0; 1
d:=0;
while (x<y) { 2
x:=x+3;
y:=y+2; 3
Example:
Program has 100 statements
Tests exercise 87 statements
Statement coverage = 87%
A coverage item is whatever we have been able to count
and see whether a test has exercised or used this item.
NB! 100% coverage does not mean that 100% tested!
Using structural coverage
Spe Enough
c Software tests?
Tests
Results OK?
What's
covered
More tests ? Coverage OK?
Stronger structural
techniques (different
structural elements)
Increasing coverage
The test coverage trap
Structure exercised,
insufficient function
Coverage Measure
= number of executed statements/ total number of statements
Statement Coverage
Example
Consider this example: a
public int test02( int a,
a>1
Y
int b, int x) { AND
b==0
c
if (a>1 && b==0) {
x = x/a; b N
} x = x/a
if (a==2 || x>1) {
a==2
x = x+1; OR
x>1
Y
e
}
return x; d N
} x=x+1
ID Input path Expected
output
1 (2, 0, 6) acef 4
f
x = x+1;
a==2
} OR
x>1
Y
e
return x;
N
}
ID Input path Expected
output d x=x+1
1 (2, 0, 6) acef 4
2 (4, 3, 1) abdf 1
f
Branch or decision coverage is to test each branch at least once.
All branches covered for paths
ACEF & ABDF, OR
ABEF & ACDF
Note: without detailed analysis of the condition causing the branch.
Branch/Decision Coverage
x = x/a
b x = x/a
a==2
a==2
OR Y
e OR
x>1
Y
e
x>1
d N
N
d x=x+1
x=x+1
f f
Branch/Decision Coverage
a
Example 3: ID: 3
Y
ID: 1
String result=null;
e
if (value > 0) value < Y
0
result="red";
N
else if (value < 0)
result="blue"; d blue
else
result="green"; green
return result;
}
f
ID Input path Expected output
12 12 123 ?
? ? ? ?
?
Paths through code with loops
1 2 3 4 5 6 7 8 ….
End
Example 2
Read
End
3
Cyclomatic complexity: _____
Minimum tests to achieve:
1
Statement coverage: ______
3
Branch coverage: _____
Example 3
Read
Read A Yes No
Read B A>0 B=0 Print
IF A > 0 THEN No Yes
Yes
IF B = 0 THEN Print A>21 Print
Print “No values”
No
ELSE
Print B
IF A > 21 THEN End
Print A 4
Cyclomatic complexity: _____
ENDIF
ENDIF Minimum tests to achieve:
ENDIF Statement coverage: ______
2
4
Branch coverage: _____
Yes
Example 4
Read A<0 Print
No
Yes
Read A<0 Print
Read A No
Read B
IF A < 0 THEN
Yes
Print “A negative” B<0 Print
ENDIF No
IF B < 0 THEN
Print “B negative”
ENDIF End
3
Cyclomatic complexity: _____
Minimum tests to achieve:
1
Statement coverage: ______
2
Branch coverage: _____
Example 6
Yes
Read A<0 Print
No
Read A
Yes
IF A < 0 THEN A>0 Print
Print “A negative”
No
ENDIF
IF A > 0 THEN
Print “A positive” End
ENDIF
3
Cyclomatic complexity: _____
Minimum tests to achieve:
2
Statement coverage: ______
2
Branch coverage: _____
Decision coverage
(Branch coverage)
Decision coverage
percentage of decision outcomesis normally measured
exercised by a test suite by a software tool.
if A or B then
A B Branch
s1
test 1 T F true
else
s2 test 2 F F false
end_if_then_el
se
Condition Coverage (cont’d)
if A or B then
A B Branch
s1
else test 3 T F true
s2 test 4 F T true
end_if_then_el
se
Condition coverage
This is closely related to decision coverage but has better sensitivity to
the control flow.
Condition coverage reports the true or false outcome of each condition.
Condition coverage ensures that every possible condition is executed at
least once
public int test04(int a, int b,
int x) {
a
a < 0
if (a < 0 && b > 20) Y
x = x + 1;
&& b >
20
c
else N
x = x * 2; b red
return x; blue
}
ID a<0 b>20 x Expected output
1 True -1 True 21 2 3 N
2 True -1 False 19 2 4 d
3 False 1 True 21 2 4
4 False 1 False 19 4 8
Condition coverage
Example 2
Each condition in a decision outcome covered by a test case
This is often considered impossible to achieve this form of
coverage a
Test cases cover 8 combinations: a>1
AND
Y
c
a>1, b=0 T
b==0
N
a>1, b!=0 T F
b
F T
a<=1, b=0 F
x = x/a
1-10 11-20
21-50 >50
Complex Untestable
High risk Very high risk
Cyclomatic Complexity (CC)
statement1
statement2
if (x > 5) {
… V(G) = 1 V(G) = 2
statement1
statementn }
if (x > 5) {
statement1
} else {
V(G) = 2
statement2
}
Cyclomatic Complexity Examples
switch (exp) {
case v1: statement1; break;
case v2: statement2; break;
if (x > 5 || x <= 10) {
…
statement1
case vn: statementn; break; V(G) = 3
}
default: statementn+1;
} if (x >= 0 && x <= 100) {
statement1
V(G) = n + 1 } else if (x <= 30) {
V(G) = 4 statement1
} else {
statement2
}
Cyclomatic Complexity Examples
1
• The test development process
2
• Categories of test design techniques
3
• Black and White box testing
4
• Black box test techniques
5
• White box test techniques
6
• Experience-based techniques
7
• Choosing a test technique
60
Experience-based techniques
Test cases are derived from the tester’s skill and intuition,
and their experience with similar applications and
technologies.
Can be helpful in identifying tests that were not easily
identified by other more systematic techniques.
Depending on tester’s approach and experience, these
techniques may achieve widely varying degrees of coverage
and effectiveness.
Coverage can be difficult to assess
and may be unmeasurable with these
techniques.
Error Guessing
1
• The test development process
2
• Categories of test design techniques
3
• Black and White box testing
4
• Black box test techniques
5
• White box test techniques
6
• Experience-based techniques
7
• Choosing a test technique