MES3053 Software Testing and Quality

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 31

MES3053

Software Testing and Quality


White-Box Testing
Learning Objectives
To describe the term White-box
To describe the importance and role of white-box testing
approach
To describe the white-box testing techniques
To design test cases using the white-box testing techniques
such as:
Basis Path Testing
Control Structure testing

2
Introduction
White-box testing (WBT) approach requires internal structure
of programs to be observed by testers.
Test development such as test case selection and test oracle
development are based on the components implementation.
WBT is a strong verification technique through which tester
examine if code works as expected.
With this approach, logical paths through the software are
tested by providing test cases that exercise specific sequence
of instructions, condition and/or loops.
The objective of WBT is to ensure that all statements &
conditions have been executed at least once.

3
The Idea of White-Box
Looks inside the box to verify SW
components & functions by examining
each line of code & data structures SUT

INPUT OUTPUT
input

4
White-box Testing Concept
It is also known as structural testing or code-base testing.
Test case are derived based from the program structure.
Required code to be completed in advance.
In WBT approach, includes the execution of the following:
All independent paths within a module at least once,
All logical decision on their true and false sides,
All loops at their boundaries within their operational bounds, and
All internal data structure to assure their validity

5
The advantage of WBT
Easy to find out which type of input/data
help in testing the application effectively.
It helps to optimizing the code.
It can help to determine the location of a
problem.
It helps in removing the extra lines of code,
which can bring in hidden defects.

6
The disadvantages of WBT
As knowledge of code and internal structure
is a prerequisite, a skilled tester is needed to
carry out this type of testing, which
increases the cost.
It is nearly impossible to look into every bit
of code to find out hidden errors, which may
create problems, resulting in failure of the
application.

7
WB Approaches
Flow Graph Notation
A circle in a graph represents a node, which stands for a sequence of
one or more procedural statements
A node containing a simple conditional expression is referred to as a
predicate node
Each compound condition in a conditional expression containing one or
more Boolean operators (e.g., and, or) is represented by a separate
predicate node
A predicate node has two edges leading out from it (True and False)
An edge, or a link, is a an arrow representing flow of control in a specific
direction
An edge must start and terminate at a node
An edge does not intersect or cross over another edge
Areas bounded by a set of edges and nodes are called regions
When counting regions, include the area outside the graph as a region,
too 10
Flow Graph Notions
sequence selection

if.. then..else
until loop

case
while loop

11
Flow Graph Example
FLOW CHART FLOW GRAPH
0 0

1 1

2 R4 2
3 R3
3

6 4 6 4
R2
7 8 5 7 8 5
R1
9
9
11 10 11 10 12
Independent Program Paths
Defined as a path through the program from the start node
until the end node that introduces at least one new set of
processing statements or a new condition (i.e., new nodes)
Must move along at least one edge that has not been
traversed before by a previous path
Basis set for flow graph on previous slide
Path 1: 0-1-11
Path 2: 0-1-2-3-4-5-10-1-11
Path 3: 0-1-2-3-6-8-9-10-1-11
Path 4: 0-1-2-3-6-7-9-10-1-11

13
A Second Flow Graph Example
1 int functionY(void) 3
2 {
3 int x = 0;
4 int y = 19; 4
5 A: x++; 5
6 if (x > 999)
7 goto D;
8 if (x % 11 == 0) 6
9 goto B;
10 else goto A;
8 7
11 B: if (x % y == 0) 10 9 16
12 goto C;
13 else goto A; 11 17
14 C: printf("%d\n", x); 13 12
15 goto A;

16 D: printf("End of list\n"); 14
17 return 0;
18 } 15 14
A Sample Function to Diagram and Analyze
1 int functionZ(int y)
2 {
3 int x = 0;

4 while (x <= (y * y))


5 {
6 if ((x % 11 == 0) &&
7 (x % y == 0))
8 {
9 printf(%d, x);
10 x++;
11 } // End if
12 else if ((x % 7 == 0) ||
13 (x % y == 1))
14 {
15 printf(%d, y);
16 x = x + 2;
17 } // End else
18 printf(\n);
19 } // End while

20 printf("End of list\n");
21 return 0;
22 } // End functionZ
15
A Sample Function to Diagram and Analyze
1 int functionZ(int y)
2 { 3
3 int x = 0;

4 while (x <= (y * y)) 4


5 {
6 if ((x % 11 == 0) &&
7 (x % y == 0)) 6
8 {
9 printf(%d, x);
10 x++; 12 9
11 } // End if
12 else if ((x % 7 == 0) ||
13 (x % y == 1)) 10
14 { 15
15 printf(%d, y);
16 x = x + 2;
17 } // End else 16
18 printf(\n);
19 } // End while 18
20 printf("End of list\n");
21 return 0; 20
22 } // End functionZ
16
21
Example

3
FLOW CHART
4
6

7 8 5

9
1
0
11

17
edges nodes
1

R4
2,3

R1
6
4,5
R2
R3
7 8

region
9

10

FLOW GRAPH 11
18
Independent Path
Path 1: 1-11
Path 2: 1-2-3-4-5-10-1-11
Path 3: 1-2-3-6-8-9-10-1-11
Path 4: 1-2-3-6-7-9-10-1-11
*predicate nodes are the nodes which having condition such as nodes (1),(2,3),(6)

19
Exercise:
Transfer the above flow chart to
flow graph, then identify:
region
the number of nodes 1
the number of edge/link

4 6

7 5 20
Exercise
1
Things to do:-
2
Transfer the flow chart to flow
graph 5 3 4
Identify the region
Identify the independent path 6

11 9 10

13 12
Control Structure Testing
Control structure testing controls over the order in which the
instructions in programs are executed.
Selection of test cases meet various criteria for covering the
code such as:
Statement coverage or node coverage every statement of
the program must be exercised at least once.
Branch coverage or decision coverage every possible
alternative in a branch (or decision) of the program should
be exercised at least once.
Statement Coverage
Statement Coverage requires that
each statement will have been
executed at least once.
What is the minimum number of test
cases required to achieve statement
coverage for the program segment
given below?
Branch Coverage
Summary
In this chapter you have learned how to:
To describe the term White-box
To describe the importance and role of white-box testing
approach
To describe the white-box testing techniques
To design test cases using the white-box testing techniques
such as:
Basis Path Testing
Control Structure testing

30
February 2010 31

You might also like