Académique Documents
Professionnel Documents
Culture Documents
Overview
Structural Testing
Introduction General Concepts Flow Graph Testing
DD-Paths Test Coverage Metrics Basis Path Testing Guidelines and Observations
Structural Testing
Also known as glass box, structural, clear box and open box testing. A software testing technique whereby explicit knowledge of the internal workings of the item being tested are used to select the test data. Unlike black box testing that is using the program specification to examine outputs, white box testing is based on specific knowledge of the source code to define the test cases and to examine outputs.
http://www.webopedia.com/TERM/W/White_Box_Testing.html
Structural Testing
Structural testing methods are very amenable to:
Rigorous definitions
Data flow, control flow, objectives, coverage criteria, relation to programming language semantics
Mathematical analysis
Graphs, path analysis
Precise measurement
Metrics, coverage analysis
4
Program Graph
If i, j, are nodes in the program graph, there is an edge from node i, to node j in the program graph if an only if, the statement corresponding to node j, can be executed immediately after the last statement of the group of statement(s) that correspond to node i.
The groups of statements that make up a node in the Program Graph is called a basic block. There is a straightforward algorithm to segment a code fragment into basic blocks and create the corresponding Program Graph.
6
} /* Compute the mean and print the result */ 7 if (NumberOfScores > 0) { Mean = SumOfScores / NumberOfScores; printf( The mean score is %f\n, Mean); } else printf (No scores found in file\n); 9 }
F 5
F 9
x>z
f
2 t
6
R1
R2
3
u=0 4
f 7
y = z+k
R3
u<x
10
5 10 6 14 7 21 16 17 15 11 12 13
18
19
22
20
11
DD-Paths (1)
The best known form of structural testing is based on a construct known as a decision-to-decision path. A DD-Path is a chains obtained from a program graph, where a chain is a path in which the initial and terminal nodes are distinct, and every interior node has indegree = 1, and outdegree = 1. We show in the next slide on selecting the nodes from a program graph to form a DD-Path chain. DD-Paths are used to create DD-Path Graphs. Note that the initial node is 2-connected to every other node in the chain, and there are no instances of 1- or 3- connected nodes. An example of a chain is shown below:
Initial node
Internal nodes
Final node 12
DD-Paths (2)
More formally a DD-Path is a chain obtained from a program graph such that:
Case1: it consists of a single node with indeg=0. Case2: it consists of a single node with outdeg=0, Case3: it consists of a single node with indeg 2 or outdeg 2 Case4: it consists of a single node with indeg =1, and outdeg = 1 Case5: it is a maximal chain of length 1
13
Case # 1 5 4 4 3 5 4 3
4
10
6 14 7 21 16 17 15 11 12 13
5-8 9 10 11 12-14
18
19
15 16
22
20
17
18 19 20 21 22
H
I J K L last
4
3 4 3 4 2
14
DD-Path Graph
Given a program written in an imperative language, its DD-Path graph is a labeled directed graph, in which nodes are DD-Paths pf its program graph, and edges represent control flow between successor DD-Paths.
In this respect, a DD-Path is a condensation graph. For example 2-connected program graph nodes are collapsed to a single DD-Path graph node.
15
Case # 1 5 4 4 3 5 4 3 4 3 4 3 4
5 10 6 14 7 15 11 12 13
5-8 9 10 11 12-14
21
16 17
15 16
18
19
17 18
first
22
20
19 20
A A B C E
21
22
last
16
last
Test coverage metrics are a device to measure the extend to which a set of test cases covers a program.
17
Description of Coverage
Every Statement Every DD-Path Every predicate to each outcome C1 Coverage + loop coverage C1 Coverage + every dependent pair of DD-Paths Multiple condition coverage Every program path that contains up to k repetitions of a loop (usually k=2) Statistically significant fraction of paths All possible execution paths
18
P2
20
P1
P2
21
Loop Coverage
The simple view of loop testing coverage is that we must devise test cases that exercise the two possible outcomes of the decision of a loop condition that is one to traverse the loop and the other to exit (or not enter) the loop.
An extension would be to consider a modified boundary value analysis approach where the loop index is given a minimum, minimum +, a nominal, a maximum -, and a maximum value or even robustness testing. Once a loop is tested, then the tester can collapse it into a single node to simplify the graph for the next loop tests. In the case of nested loops we start with the inner most loop and we proceed outwards. If loops are knotted then we must apply data flow analysis testing techniques, that we will examine later in the course.
24
25
The objective is to generate test cases that exercise these basis paths.
28
t
6
R1
R2
3 y = z+k
u=0 4
f 7
R3
u<x
29