9.fall 23-Lecture9StructuralTesting
9.fall 23-Lecture9StructuralTesting
Structural Testing
CSE 4495 - Lecture 8 - 30/08/2022
Instructor : Md. Mohaiminul Islam
[email protected] 1
Every developer must answer:
Are our tests are any good?
2
Have We Done a Good Job?
What we want:
• We’ve found all the faults.
• Impossible.
What we (usually) get:
• We compiled and it worked.
• We run out of time or budget.
• Inadequate.
Test Adequacy Criteria
1==x
T F
y=45; y=23456;
/* continue */
Loop
1<x
T F
/* continue */
x--;
Case
test
/* continue */
Basic Blocks
• Nodes are basic blocks.
• Set of sequential
instructions with single
int i = 0;
entry and exit point.
• Typically adjacent i < 10
statements, but one T F
sum += i;
statement might be broken i++;
up to model control flow in
the statement.
Control Flow Graph Example
1-3
int cldx = 0;
cldx <
argStr.length();
F T
13 6
7
F
T
8-9 cldx++;
Structural Coverage Criteria
• Criteria based on exercising:
• Statements (nodes of CFG)
• Branches (edges of CFG)
• Conditions
• Paths
• … and many more
• Measurements used as adequacy criteria
Statement Coverage
i=0
1 True True
(A and B) 2
3
True
False
False
True
4 False False
(A and 4
5
6
True
True
True
True
False
False
False
True
True
False
True
False
(B 7
8
9
True
True
False
False
False
True
False
False
True
True
False
True
and 10
11
12
False
False
False
True
True
True
True
False
False
False
True
False
(C and 13
14
15
False
False
False
False
False
False
True
True
False
True
False
True
1 True True
(A and B) 2 True False
3 False -
Modified Condition/Decision Coverage(MC/DC)
• Requires:
• Each condition evaluates to true/false
• Each decision evaluates to true/false
• Each condition shown to independently affect outcome
of each decision it appears in.
Test Case A B (A and B)
1 True True True
2 True False False
3 False True False
4 False False False
Modified Condition/Decision Coverage(MC/DC)
• Requires:
• Each condition evaluates to true/false
• Each decision evaluates to true/false
• Each condition shown to independently affect outcome
of each decision it appears in.
Test Case A B (A and B)
1 True True True
2 True False False
3 False True False
4 False False False
Activity
Draw the CFG and write tests that provide statement, branch, and
basic condition coverage over the following code:
Activity - Control Flow Graph
index=0
False False
A.length
False A.length
(A.length ==1)
==0 >1 return -1;
&& (A[0] = what)
True False
True index <
True
A.length
return 0; return -1; True
A[index] False
== what
index++;
Basic Condition
Branch Coverage Coverage
Power,
Cost Statement Coverage
Thank You
50