Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

1

STRUCTURAL TESTING

2
Structural Testing
 Also known as glass box ,white 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.

• Structural testing methods are very amenable (manage or accept) 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
3
Program Graph - Definition
“Given a program written in a programming language, its Program
Graph, is a directed labeled graph in which nodes are either groups of
entire statements or fragments of a statement, and edges represent flow of
control”

• 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. 4
5
White-box Testing: Determining the Basic
Blocks
FindMean (FILE ScoreFile)
{ float SumOfScores = 0.0;
int NumberOfScores = 0;
1
float Mean=0.0; float Score;
Read(ScoreFile, Score);
2 while (! EOF(ScoreFile) {
3 if (Score > 0.0 ) {
SumOfScores = SumOfScores + Score;
4
NumberOfScores++;
}

Read(ScoreFile, Score); 5
}
/* Compute the mean and print the result */
6 if (NumberOfScores > 0) {
Mean = SumOfScores / NumberOfScores;
printf(“ The mean score is %f\n”, Mean); 7
} else
printf (“No scores found in file\n”); 8
} 6
Constructing the Logic Flow Diagram
Start

F
2
T
3
T
4 F

6
T F
7 8

Exit

7
1 Program triangle2 `Structured programming version of simpler
specification
`
2 Dim a,b,c As Integer
3 Dim IsATriangle As Boolean
`
`Step1: Get Input
4 Output(“Enter the 3 integers which are sides of a triangle “)
5 Input(a,b,c)
6 Output(“Side A is “,a)
7 Output(“Side B is”,b)
8 Output(“Side C is”c)
`
`Step2:Is A Triangle?
9 If(a<b+c) AND (b<a+c) AND (c<a+b)
10 Then IsATriangle=True
11 Else IsATriangle=False
12 EndIf
`
8
`Step3:Determine Triangle Type
13 If IsATriangle
14 Then If(a=b) AND (b=c)
15 Then Output (“Equilateral”)
16 Else If( a!=b) AND (a!=c) AND (b!=c)
17 Then Output (“Scalene”)
18 Else Output (“ Isoceles”)
19 EndIf
20 EndIf
21 Else Output(“Not a Triangle”)
22 EndIf
`
23 Endtriangle2

9
10
11
Program Graph - Use
• The importance of program graph is that program executions
correspond to paths from the source to sink nodes.

• As any Test case forces the execution of some such program


path, we will know the explicit relationship between a test
case and the part of the program w.r.t testcase.

• The Figure 9.2 is a graph of simple program.


• In this program, five paths lead from node B to node F in the
interior of the loop

12
13
DD-Paths
• The best known form of structural testing is based on a
construct known as a decision-to-decision path.
• The name refers to a sequence of statements that, begins
with the “outway” of a decision statement and ends with the
“inway” of the next decision statement.
• A DD-Path is a chain 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. 14
 Notice that the initial node is 2-connected to every other node in
the chain, and no instances of 1- or 3-connected nodes occur, as
shown above.
The length (number of edges) of the chain is 6.

15
DD-Path Definition
• 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


16
DD-Path Formation - Example
Program Graph Nodes DD-Path Name Case #

4 first 1

5-8 A 5

9 B 3

10 C 4

11 D 4

12 E 3

13 F 3

14 H 3

15 I 4

16 J 3 17
DD-Path Formation - Example
Program Graph Nodes DD-Path Name Case #

17 K 4

18 L 4

19 M 3

20 N 3

21 G 4

22 O 3

23 Last 2

18

DD-Path
Definition: DD-Path Graph
Graph
• Given a program written in an imperative language, its DD-Path graph
is a labeled directed graph, in which nodes are DD-Paths of its
program graph, and edges represent control flow between
successor DD-Paths.

• The DD-Path graph is a form of condensation graph.


• Condensation graph;
• Given a graph G=(V,E) its condensed graph is formed by replacing
each component by condensing node.

• In this condensation, 2-connected components are collapsed into


individual nodes that correspond to case 5 DD-Paths.

19
Program Graph to DD-Path Graph

4 5 6 7 8

10 11

12

13

14
21
15 16

17 18
20
22
19

23
20
Topological Pathing

We can identify eight possible paths through the previous diagram

1. first – A – B – C – E – F – G – O – last
2. first – A – B – D – E – F – G – O – last
3. first – A – B – C – E – F – H – I – N – O – last
4. first – A – B – D – E – F – H – I – N – O – last
5. first – A – B – C – E – F – H – J – K – M – N – O – last
6. first – A – B – D – E – F – H – J – K – M – N – O – last
7. first – A – B – C – E – F – H – J – L – M – N – O – last
8. first – A – B – D – E – F – H – J – L – M – N – O – last

21
Feasible Paths
• If we assume that the logic of the program dictates that “if node C is
traversed, then we must traverse node H,(if istriangle=true then
if(a==b)||(b==c) and if node D is traversed, then we must traverse Node
G” if (istriangle=false) then output(“not a triangle”)
– These constraints will eliminate Paths 1, 4, 6 and 8
– Infeasible paths
1. first – A – B – C – E – F – G – O – last
4. first – A – B – D – E – F – H – I – N – O – last
6. first – A – B – D – E – F – H – J – K – M – N – O – last
8. first – A – B – D – E – F – H – J – L – M – N – O – last
• We are left to consider four feasible paths:
Feasible Paths:
2. first – A – B – D – E – F – G – O – last
3. first – A – B – C – E – F – H – I – N – O – last
5. first – A – B – C – E – F – H – J – K – M – N – O – last
7. first – A – B – C – E – F – H – J – L – M – N – O – last

22

You might also like