lec.unit testing control flow
TRANSCRIPT
1
UNIT TESTING - Complexity
Reference:
+ Software Testing Course @ Lonsdale System
+Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric
@ Arthur: H. Watson + Thomas J. McCabe
HCMUNS – FIT – SE Dept - ST Course
2
Control flow graphs
Cyclomatic complexity can be used for 2 purposes:
As a defect prevention technique
To determine the number of structural test cases that will execute all of independent paths through a program
HCMUNS – FIT – SE Dept - ST Course
3
Control flow graph
HCMUNS – FIT – SE Dept - ST Course
4
Control flow graph
HCMUNS – FIT – SE Dept - ST Course
5
Cyclomatic complexity
Complexity = number of edges –number of nodes + 2
Sequence = 1-2+2 =1
If … then ... Else = (2-2+2) = 2
Repeat … until = (3-3+2) = 2
While do … end = (3-3+2) = 2
Case = (7-5+2) = 4
HCMUNS – FIT – SE Dept - ST Course
6
HCMUNS – FIT – SE Dept - ST Course
7
HCMUNS – FIT – SE Dept - ST Course
8
Complexity = 13 -10 + 2=5
HCMUNS – FIT – SE Dept - ST Course
9
Comlexity for AND & OR
Complexity = (9-7+2) = 4
HCMUNS – FIT – SE Dept - ST Course
10
HCMUNS – FIT – SE Dept - ST Course
11
HCMUNS – FIT – SE Dept - ST Course
12
Exercise
HCMUNS – FIT – SE Dept - ST Course
13
Exercise
HCMUNS – FIT – SE Dept - ST Course
14
HCMUNS – FIT – SE Dept - ST Course
15
HCMUNS – FIT – SE Dept - ST Course
16
Alternative Approaches to Counting Complexity
Too simple
Complexity = number of decision predicates + 1
Let check examples again !