Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Path testing
Functional testing Structural testing
Control Flow Graph Graphs DD-paths Independent paths McCabes Cyclomatic Metric Derivation of test cases
2 3 4 5
7 8 9 17 11
10 12 13 16 15 14
18 19
Source node
1 2 3 4 5 7 8 9 17 11 13 16 18 15 10 12 6
1 3 4 5 6
Sequence nodes
if-then node
7 8 9 12 11
if-then-else nodes
if-then-else nodes
13 14 14 15
Sink node
19
Sink node
16
Graphs - terminology
Nodes (n) and edges (e) Directed / undirected graph Degree of a node deg(n)
The number of edges that have that node as an endpoint
Sequence
If-then-else
If-then
Case
B C D F H G E
Indegree of a node
The number of edges that have the node as a terminal node
Outdegree of a node
The number of edges that have the node as a start node
Graphs - exercise
Graphs - exercise
Specify degree of nodes A to H
A 3 B 4 C 3 D 4 E F G 3 4 3 indeg(D) = 3 outdeg(D) = 1 H 0
Specify degree of nodes A to H Specify indeg of nodes B and D Specify outdeg of nodes B and D What is indeg of the source node? What is outdeg of the sink node? Compute the cyclomatic number of the graph
Specify outdeg of nodes B and D What is indeg of the source node? What is outdeg of the sink node?
Always 0
DD-path graphs
1 2 3 4 5
A CFG can be broken into DD-paths Each DD-path is collapsed into an individual node The resulting graph is called a DD-path graph of the program Every node in a DD-path graph is equivalent to a predicate Case 1 Src Other cases: C3
C4 C4 C3 C3 C4 C3
Case 5
Case 2
1 2 3 4 5 7 8 9 17 11
DD-path graph
Src A B
C
6
E F
10 12 13 16 15 14
G I
H J K N M L
18 19
O Snk
Src A B
Independent paths
Find at least one independent path in the graph
Src A B D
Src-A-B-D-E-F-H-J-K-M-N-O-Snk Src-A-B-D-E-F-H-J-L-M-N-O-Snk Src-A-B-D-E-F-H-I-N-O-Snk Src-A-B-C-E-F-G-O-Snk Src A B D E F G I H J K N O Snk M O Snk L N G I K M O Snk C E F H J L N G I K M O Snk D C E F H J L N G I K M Src A B D C E F H J L Src A B D
C E F G I
H J K N M L
O Snk
?
Independent paths
Src A B C E F G I K N O Snk M O Snk H J L N G I K M O Snk D C E F H J L N G I K M O Snk Src A B D C E F H J L N if IsATriangle G I K M Src A B D C E F H J L IsATriangle = F Src A B D
Lesson: Paths must be feasible Generating independent paths Generate one feasible path (a baseline path) Generate further paths by flipping each decision point in turn
Decision point is a node with outdegree 2 Flipping is taking a different edge than those taken previously A technically feasible path may not be feasible logically (according to the logic of the program)
...
If-then-else
If-then
Case
V(G) = e n + 2p
gives (approximately!) the number of independent paths
Pre-test loop
Post-test loop
Src A B C E F G I K N O Snk G M H J L C F D
Exercise
V(G) = e n + 2p
V(G) = 20 17 + 2 = 5 Five independent paths
B
A D E
V(G) = e n + 2p
V(G) = 10 7 + 2 = 5 5 independent paths
P1: P2: P3: P4: P5: A-B-C-G A-B-C-B-C-G A-B-E-F-G A-D-E-F-G A-D-F-G
Generate test cases in the same way as the Independent Paths are generated
i.e. each test case will represent a different combination of the states of the Gate Variables
Src A B C E F G I K N O M H J L D Src A
Src A B
B D C E F H I J K L M N G O Snk
Snk
B D C E F H I J K L M N G O Snk
C E F G I
H J K N M L
O Snk
DD-path testing
Testing which covers every DD-path is a minimum industry accepted level of test coverage of the source code It is called path coverage metric, C1 This and other metrics (C0, C0p, C2, Cd, CMCC, Cjk, Cstat, C) are primarily criteria that measure the quality of testing and not a procedure to identify test cases. [McCabe]
Concatenated loop
Nested loop
pre-test loop
For nested loop, repeat from the innermost loop and work outwards
Next lecture
Specify all the directed paths between nodes C and Snk for the graph on the left.