Bcse301l Se Module-5a Smsatapathy
Bcse301l Se Module-5a Smsatapathy
L T P C
BCSE301L - 3 0 0 3
BCSE301P - 0 0 2 1
Dr. S M SATAPATHY
Associate Professor Sr.,
School of Computer Science and Engineering,
VIT Vellore, TN, India – 632 014.
Module – 5
2. Testing Fundamentals
2
Module - 5
3
White-box testing
Debugging
Unit, Integration, and System testing
Module - 5
4
Introduction to Testing.
White-box testing:
statement coverage
path coverage
branch testing
condition coverage
Cyclomatic complexity
Module - 5
5
A failure is a manifestation of
an error (aka defect or bug).
mere presence of an error may
not lead to a failure.
Error, Faults, and Failures
10
product right?"
Validation: "Are we building the right
product?
Verification versus Validation
16
Verification Validation
Verification is the process to find whether the The validation process is checked whether
software meets the specified requirements the software meets requirements and
for particular phase. expectation of the customer.
It estimates an intermediate product. It estimates the final product.
The objectives of verification is to check The objectives of the validation is to check
whether software is constructed according to whether the specifications are correct and
requirement and design specification. satisfy the business need.
It describes whether the outputs are as per It explains whether they are accepted by the
the inputs or not. user or not.
Verification is done before the validation. It is done after the verification.
Plans, requirement, specification, code are Actual product or software is tested under
evaluated during the verifications. validation.
It manually checks the files and document. A computer software or developed program
based checking of files and document.
Activities: Reviews, Walkthroughs, Testing
Inspections
Who tests the Software?
17
Testing Myths
18
For OO software
our focus when “testing in the small” changes from an
individual module (the conventional view) to an OO
class that encompasses attributes and operations and
implies communication and collaboration
21
Design of Test Cases
Exhaustive testing of any non-trivial
system is impractical:
input data domain is extremely large.
Design an optimal test suite:
of reasonable size and
uncovers as many errors as possible.
22
Design of Test Cases
If test cases are selected randomly:
many test cases would not contribute to the
significance of the test suite,
would not detect errors not already being detected
by other test cases in the suite.
Number of test cases in a randomly selected test
suite:
not an indication of effectiveness of testing.
23
Design of Test Cases
Testing a system using a large number of
randomly selected test cases:
does not mean that many errors in the system
will be uncovered.
Consider an example for finding the
maximum of two integers x and y.
24
Design of Test Cases
The code has a simple programming error:
If (x>y) max = x;
else max = x;
test suite {(x=3,y=2);(x=2,y=3)} can detect the
error,
a larger test suite {(x=3,y=2);(x=4,y=3);
(x=5,y=1)} does not detect the error.
25
Design of Test Cases
Systematic approaches are
required to design an optimal test
suite:
each test case in the suite should
detect different errors.
26
Design of Test Cases
There are essentially two main
approaches to design test cases:
Black-boxapproach
White-box (or glass-box) approach
Black-box Testing
27
1 5000
Equivalence Class Partitioning
34
1 5000
37
Example (cont.)
The test suite must include:
representatives from each of the three
equivalence classes:
a possible test suite can be:
{-5,500,6000}.
1 5000
Boundary Value Analysis
38
An automated tool:
takes program source code as input
produces reports regarding several
important characteristics of the program,
such as size, complexity, adequacy of
commenting, adherence to programming
standards, etc.
Program Analysis Tools
55
System testing
68
Unit testing
During unit testing, modules are
tested in isolation:
Ifall modules were to be tested
together:
it may not be easy to determine
which module has the error.
69
Unit testing
Unit testing reduces debugging
effort several folds.
Programmers carry out unit testing
immediately after they complete
the coding of a module.
70
Unit testing
71
Unit testing
Integration testing
72
bottom-up approach
mixed approach
Example Structured Design
76
Big bang Integration Testing
77
Acceptance Testing
87
Alpha Testing
System testing is carried out by the
test team within the developing
organization.
88
Beta Testing
System testing performed by a
select group of friendly customers.
Acceptance Testing
89
remaining defects:
N - n = n ((S - s)/ s)
95
Example
100 errors were introduced.
90 of these errors were found during
testing
50 other errors were also found.
Remaining errors=
50 (100-90)/90 = 6
96
Error Seeding
The kind of seeded errors should match
closely with existing errors:
However, it is difficult to predict the types of
errors that exist.
Categories of remaining errors:
canbe estimated by analyzing historical data
from similar projects.
White-box Testing
97
path coverage
condition coverage
mutation testing
Statement coverage
methodology:
design test cases so that
every statement in a program is
executed at least once.
Statement Coverage
101
2 if (x>y) then
3 x=x-y;
4 else y=y-x;
5 }
6 return x; }
Euclid's GCD computation algorithm
105
2 if (x>y) then
3 x=x-y;
4 else y=y-x;
5 }
6 return x; }
Example
110
Condition testing
stronger testing than branch testing:
Branch testing
stronger than statement coverage testing.
Condition coverage
115
Condition coverage-based
testing technique:
practical only if n (the number
of component conditions) is small.
Path Coverage
117
2 if (x>y) then
3 x=x-y;
4 else y=y-x;
5 }
6 return x; }
Example Control Flow Graph
124
1
2
3 4
5
6
How to draw Control flow graph?
125
Sequence:
1 a=5; 1
2 b=a*b-1;
2
How to draw Control flow graph?
126
Selection:
1 if(a>b) then
1
2 c=3;
3 else c=5; 2 3
4 c=c*c; 4
How to draw Control flow graph?
127
Iteration:
1
1 while(a>b){
2 b=b*a;
2
3 b=b-1;}
4 c=b+d;
3
4
128
Path
A path through a program:
a node and edge sequence from the starting node to a
terminal node of the control flow graph.
There may be several terminal nodes for program.
Independent path
129
It is straight forward:
to identify linearly independent paths
of simple programs.
For complicated programs:
itis not so easy to determine the
number of independent paths.
131
McCabe's cyclomatic metric
An upper bound:
forthe number of linearly independent
paths of a program
Provides a practical way of
determining:
the maximum number of linearly
independent paths in a program.
132
McCabe's cyclomatic metric
Given a control flow graph G,
cyclomatic complexity V(G):
V(G)= E-N+2
N is the number of nodes in G
E is the number of edges in G
133
Example Control Flow Graph
1
2
3 4
5
6
Example
134
Cyclomatic complexity =
7-6+2 = 3.
Cyclomatic complexity
135
3 4
6
138
Example
From a visual examination of the CFG:
the number of bounded areas is 2.
cyclomatic complexity = 2+1=3.
Cyclomatic complexity
139
independent paths.
Prepare test cases:
6 return x; }
Example Control Flow Diagram
150
3 4
6
Derivation of Test Cases
151
WinRunner: UI testing
IBM Rational
Rational Robot
Functional Tester
Borland
Silk Test
Compuware
QA Run
AutomatedQA
TestComplete
Data Flow-Based Testing
156
1 X(){
2 a=5; /* Defines variable a */
3 While(C1) {
4 if (C2)
5 b=a*a; /*Uses variable a */
6 a=a-1; /* Defines variable a */
7 }
8 print(a); } /*Uses variable a */
Definition-use chain (DU chain)
160
[X,S,S1],
S and S1 are statement numbers,
X in DEF(S)
X in USES(S1), and
1 X(){
2 B1; /* Defines variable a */
3 While(C1) {
4 if (C2)
5 if(C4) B4; /*Uses variable a */
6 else B5;
7 else if (C3) B2;
8 else B3; }
9 B6 }
Data Flow-Based Testing
164
[a,1,5]: a DU chain.
Assume:
DEF(X) = {B1, B2, B3, B4, B5}
USED(X) = {B2, B3, B4, B5, B6}
A mutated program:
tested against the full test suite of the program.
If there exists at least one test case in the test suite
for which:
a mutant gives an incorrect result,
then the mutant is said to be dead.
Mutation Testing
168
A B
If A then B
A
C
B
If (A and B)then C
Drawing Cause-Effect Graphs
177
A
C
B
If (A or B)then C
A
C
B
If (not(A and B))then C
Drawing Cause-Effect Graphs
178
A
C
B
If (not (A or B))then C
A B
If (not A) then B
Cause effect graph- Example
179
Situation:
The “Print message” is software that read two characters
and, depending on their values, messages must be printed.
The first character must be an “A” or a “B”.
The second character must be a digit.
If the first character is an “A” or “B” and the second character
is a digit, the file must be updated.
If the first character is incorrect (not an “A” or “B”), the
message X must be printed.
If the second character is incorrect (not a digit), the message
Y must be printed.
Cause effect graph- Example
180
let’s start with Effect E1. Effect E1 is to update the file. The file is
updated when
– The first character is “A” and the second character is a digit
– The first character is “B” and the second character is a digit
– The first character can either be “A” or “B” and cannot be both.
effect:
listeach combination of causes that can lead
to that effect.
Cause effect graph- Example
189
In phased integration,
a group of related modules are added
to the partially integrated system each
time.
Big-bang testing:
a degenerate case of the phased
integration testing.
Phased versus Incremental
193
Integration Testing
Phased integration requires less number of
integration steps:
compared to the incremental integration
approach.
However, when failures are detected,
it is easier to debug if using incremental
testing
since errors are very likely to be in the newly
integrated module.
System Testing
194
Verify that:
allrequired artifacts for maintenance
exist
they function properly
Documentation tests
208
report formats
chemical presence
portability
Specifies:
how many tests have been applied to a subsystem,
how many tests have been successful,
how many have been unsuccessful, and the degree to
which they have been unsuccessful,
e.g.whether a test was an outright failure
or whether some expected results of the test were actually
observed.
Regression Testing
214