Tải bản đầy đủ (.pdf) (30 trang)

Software Testing Structural Testing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (13.41 MB, 30 trang )

Structural Testing
What is Structural Testing?
 Based on Source Code
 Examine the internal structure of the program
 Test cases are derived from an examination of program‘s logic
 Do not pay any attention to specification.
 The knowledge to the internal structure of code can be used to find the number of
test cases required to guarantee a given level of test coverage.
Why Structural Testing is Required?
 Part of code not fully exercised.
 Section of code may be surplus to the requirements.
 Errors may be missed by functional requirements.
Levels of Coverage
Levels of Coverage
 1. Statement (Line) coverage
 2. Decision (Branch) coverage
 3. Condition coverage
 4. Decision/Condition coverage
 5. Multiple Condition coverage
 6. Loop coverage
 7. Path coverage
Levels of Coverage
Levels of Coverage
Statement Coverage
Statement Coverage
Levels of Coverage
Levels of Coverage
Branch Coverage
Branch Coverage
Levels of Coverage
Levels of Coverage


Branch Coverage
Branch Coverage
Levels of Coverage
Levels of Coverage
Condition Coverage
Condition Coverage
 Condition coverage reports
the true or false outcome of
each boolean sub-expression,
separated by logical-and and
logical-or if they occur.
Condition coverage measures
the sub-expressions
independently of each other.
Levels of Coverage
Levels of Coverage
Decision/Condition Coverage
 A hybrid metric composed by the union of condition
coverage and decision coverage
Levels of Coverage
Levels of Coverage
Multiple Condition Coverage
Levels of Coverage
Levels of Coverage
Loop Coverage
 This metric reports whether you executed each loop body
zero times, exactly once, and more than once.

Path Testing(1)
 Group of test techniques based on judicious selecting a set of

test paths through the program
 Most applicable to new software for module testing or unit
testing
 The effectiveness of path testing rapidly deteriorates as the
size of the software under test increases.
Path Testing(2)
This type of testing involves:
 Generating a set of paths that will cover every branch in
the program.
 Finding the set of test cases that will execute every path in
this set of program paths.
Steps Involved in Path testing:
 Generate flow graph of a program.
 Generate DD path graph.
 Identify independent paths
Path Testing
Flow Graph (1)
 Used to analysis the control flow of a program
 Definition: Given a program written in a programming
language, its program graph is a directed graph in which
nodes are statement fragments, and edges represent flow
of control.
 If I and J are nodes in the program graph, an edge exists
from node I to node J if the statement fragment
corresponding to node J can be executed immediately
after the statement fragment corresponding to node I.
Path Testing
Flow Graph (2)
Sequence
If then else

While loop
Repeat
until loop
Case
Path Testing
Flow Graph (3)
 Example:
1. Triangle (a, b, c: Integer): String
2. IsATriangle: Boolean
3. begin
4. if (a<=b+c or b<=a+c or
c<=b+c)
5. then IsATriangle := true
6. else IsATriangle := false ;
7. if (IsATriangle)
8. then
9. if (a=b and b=c)
10. then return “Equilateral”
11. else
12. if (ab and ac and bc)
13. then return “Scalene”
14. else return “Equilateral” ;
15. else return “Not a triangle” ;
16. end
5. IsATriangle := true
7. IsATriangle?
9. (a=b and b=c)?
10. “Equilateral”
13. “Scalene”
14. “Equilateral”

16. end
4. (a<=b+c or b<=a+c or c<=b+c)?
yes
no
yes
yes
yes
no
no
no
12. (ab and ac and bc)?
6. IsATriangle := false
15. “Not a triangle”
3. begin
3
4
5 6
7
9
15
10
12
13 14
16
Path Testing
DD Path Graph (1)
 Decision to decision path graph.
 DD path graph is a directed graph in which nodes are
sequences of statements and edges represent control
flow between node.

 Used to find independent path
Path Testing
DD Path Graph (2)
 Example:
137 8 9 10 11 12
14
15 16 17 18 19
20
21 22 23 24
25 26
27
28
29
30
31
32
33
34
35 38
36
37
40
39
41 42
A
B
C
D
E
F

G
H
I
J
K
L
Path Testing
Independent Path (1)
 An independent path is any path through the program
that introduces at least one new set of processing
statements or a new condition.
 When stated in terms of a flow graph, an independent
path must move along at least one edge that has not
been traversed before the path is defined.
Path Testing
Independent Path (2)
 Independent paths are:
 ABGOQRS
 ABGOPRS
 ABCDFGOQRS
 ABCDEFGOPRS
 ABGHIJNRS
 ABGHIKLNRS
 ABGHIKMNRS
A
B
C
D
E
F

G
H
I
J
K
L
M
N
S
R
O
P
Q
Path Testing
Computation of cyclomatic complexity (1)
 Structural Complexity.
 Given by McCabe.
 Used to find number of independent paths through the
program.
 Provides an upper bound on the number of tests that
must be conducted to ensure that all statements have
been executed at lest once.
Path Testing
Computation of cyclomatic complexity (2)
 Cyclomatic complexity has a foundation in graph
theory and is computed in the following ways:
 1. V(G) = E – N + 2P
E: number of edges
N: number of nodes
 2. V(G) = P + 1

P: number of predicate nodes
 3. V(G)= number of region
Path Testing
Computation of cyclomatic complexity (3)
 1. V(G)= E–N+2=?
 2. V(G)= P + 1=?
 3. V(G)= No regions= ?
Path Testing
Example
 Consider the program for the classification of a triangle
(pages 399)


Compute cyclomatic complexity
Compute cyclomatic complexity
based on the graph that
based on the graph that
presented in page 401
presented in page 401


Determine independent
Determine independent


Generate test cases which are coverage independent path
Generate test cases which are coverage independent path
Data Flow Testing (1)
 Data flow testing focuses on the points at which
variables receive values and the points at which these

values are used (or referenced). It detects improper use
of data values due to coding errors.

×