Uploaded by lagofa2357

lec4

advertisement
Mona Fahmy Ismail
mona.ismail@eng.asu.edu.eg
SOFTWARE TESTING
CSE337
▪ Ain Shams University
▪ Faculty of Engineering
Types of SW Testing (White box)
Spring 2022
1. Types of testing
2. Manual Testing
3. White Box Testing
3
Types of testing (WB)
Mona Ismail
Spring 2022
4
Types of testing (WB)
Mona Ismail
Spring 2022
1. Types of testing
2. Manual Testing
3. White Box Testing
5
Types of testing (WB)
Mona Ismail
Spring 2022
http://www.guru99.com/manual-testing.html
6
Types of testing (WB)
Mona Ismail
Spring 2022
1. Types of testing
2. Manual Testing
3. White Box Testing
7
Types of testing (WB)
Mona Ismail
Spring 2022
http://www.guru99.com/white-box-testing.html
▪ White Box Testing (WBT) is the method in which internal structure of
the SW is being completely known to tester to:
▪ Identify the weakness in the software under test in early stage of
software development life cycle
▪ Derive test cases, provide input to the system, and check for
expected outputs based on the specification document with actual
output.
8
Types of testing (WB)
Mona Ismail
Spring 2022
▪ Helps in removing the bugs
▪ Covering all possible paths of code
▪ No need to wait for the GUI, to start the testing of
▪
▪
▪
▪
the software
Tester can ask about implementation of each
section, so it might be possible to remove unused
lines of code which might be introducing a bug.
By executing equivalence use to approximates the
partitioning
As the tester is aware of internal coding structure,
then it is helpful to derive which type of input data
is needed to test software application effectively.
White box testing helps in the code optimization.
Types of testing (WB)
Mona Ismail
Spring 2022
9
▪ It very expensive type of testing that requires a highly skilled
tester with deep knowledge of internal structure of the code.
▪ Update test script is required if changing the implementation
too frequently.
▪ If the application under test is of large size then exhaustive
testing and testing every path/condition of software are
impossible.
▪ To analyze each line or path is nearly impossible work which
may introduce or miss the defects in the code.
▪ To test each paths or conditions may require different input
conditions to create full range of inputs which may be a time
consuming.
Types of testing (WB)
Mona Ismail
Spring 2022
10
▪ There exist several popular white-box testing methodologies:
o Statement coverage
o Branch coverage
o Condition coverage
o Path coverage
11
Types of testing (WB)
Mona Ismail
Spring 2022
▪ Statement coverage methodology:
▪ Design test cases so that every statement in a program is
executed at least once to ensure if an error exists in that
statement
▪ Observing that a statement behaves properly for one input
value does not guarantee that it will behave correctly for all
input values
12
Types of testing (WB)
Mona Ismail
Spring 2022
int f1(int x, int y){
while (x != y){
if (x>y) then
x=x-y;
else y=y-x;
}
return x;
}
▪ By choosing the test set {(x=3,y=3),(x=4,y=3), (x=3,y=4)}
o all statements are executed at least once
13
Types of testing (WB)
Mona Ismail
Spring 2022
▪ There exist several popular white-box testing methodologies:
o Statement coverage
o Branch coverage
o Condition coverage
o Path coverage
14
Types of testing (WB)
Mona Ismail
Spring 2022
▪ Test cases are designed such that:
▪ different branch conditions given true and false values in
turn
▪ Branch coverage testing guarantees statement coverage
▪ a stronger testing compared to the statement coverage-
based testing
▪ Stronger testing:
▪ discovers as many errors as a weaker testing
▪ contains as many significant test cases as a weaker test
15
Types of testing (WB)
Mona Ismail
Spring 2022
int f1(int x,int y){
while (x != y){
if (x>y) then
x=x-y;
else y=y-x;
}
return x;
}
Test cases for branch coverage can be:
{(x=3,y=3),(x=3,y=2), (x=3,y=4)}
16
Types of testing (WB)
Mona Ismail
Spring 2022
A
if (B) C
else D
For statement coverage, it
is enough to have B true Run 1:
B = false
and false and F is true
E
Full branch coverage
implies Full statement
I
coverage
For branch coverage, both B
and F would have to each Run 1:
B = false
be false and true each
if (F) G
Types of testing (WB)
Mona Ismail
F = true or false
# executes A B _ D E F G I
Run 2:
B = true
F = true or false
# executes A B C _ E F G I
F = false
# executes A B _ D E F _ I
Run 2:
B = true
F = true
# executes A B C _ E F G I
Spring 2022
17
A;
for (int i = 0; i < length; ++i)
B;
C;
Statement coverage
requires loop to
execute at least once
Branch coverage
requires loop to
execute zero and once
18
▪ There exist several popular white-box testing methodologies:
o Statement coverage
o Branch coverage
o Condition coverage
o Path coverage
19
Types of testing (WB)
Mona Ismail
Spring 2022
▪ Test cases are designed to cover each component of a
composite conditional expression
o given both true and false values
▪ Branch testing is the simplest condition testing strategy
n
▪ 2 test cases are required to test a Boolean expression
having n components for condition coverage
▪ Practically, Condition coverage-based testing technique is
used only if n (the number of component conditions) is
small
20
Types of testing (WB)
Mona Ismail
Spring 2022
▪ Condition usually covers branch
▪ It attempts the code with many possible combination more
than branch or statement coverage
Example
Consider the conditional expression
((c1.and.c2).or.c3)
Each of c1, c2, and c3 are exercised at least once, given true
and false values
21
Types of testing (WB)
Mona Ismail
Spring 2022
If ((x > y + z) & (y < -3)) OR ((z2 + x2 < 4) & (z <= y)) ….
22
Types of testing (WB)
Mona Ismail
Spring 2022
If ((x > y + z) & (y < -3)) OR ((z2 + x2 < 4) & (z <= y)) ….
23
Types of testing (WB)
Mona Ismail
Spring 2022
▪ There exist several popular white-box testing methodologies:
o Statement coverage
o Branch coverage
o Condition coverage
o Path coverage
24
Types of testing (WB)
Mona Ismail
Spring 2022
▪ Path testing is a structural testing method that find every
possible executable path
▪ It helps to determine all faults lying within a piece of code
▪ Any software program includes, multiple entry and exit
points
▪ Testing each of these points is a challenging as well as
time-consuming
▪ In order to reduce the redundant tests and to achieve
maximum test coverage, basis path testing is used
25
Types of testing (WB)
Mona Ismail
Spring 2022
The basic steps involved in basis path testing include:
Draw Control Flow Graph
(CFG) of a program (to
determine different
program paths)
Calculate Cyclomatic
complexity metrics V(G)
(to determine the number
of independent paths)
Find a basis set of paths
Generate test cases to
exercise each path
Types of testing (WB)
Mona Ismail
26
Spring 2022
▪ Flow Graph notation for a program defines
several nodes connected through the edges
▪ Those are Flow diagrams for:
Types of testing (WB)
Mona Ismail
Spring 2022
27
▪ Number all the statements of a program
▪ Numbered statements represent nodes of the control flow
graph
▪ An edge from one node to another node exists when
execution of the statement representing the first node can
result in transfer of control to the other node
Sequence:
1 a=5;
2 b=a*b-1;
1
2
28
Types of testing (WB)
Mona Ismail
Spring 2022
▪ If-than-else
1 if(a>b) then
2
c=3;
3 else c=5;
4 c=c*c;
1
2
3
4
1
▪ While
1 while(a>b){
2
b=b*a;
3
b=b-1;}
4 c=b+d;
2
3
4
Types of testing (WB)
Mona Ismail
29
Spring 2022
int f1(int x, int y){
1 while (x != y){
2 if (x>y) then
3
x=x-y;
4 else y=y-x;
5 }
6 return x;
}
1
2
3
4
5
6
Types of testing (WB)
Mona Ismail
Spring 2022
30
Cyclomatic Complexity in
Software Testing
▪ Cyclomatic Complexity in Software Testing is a testing
metric used for measuring the complexity of a software
program
▪ It is a quantitative measure of independent paths in the
source code of a software program
▪ Cyclomatic complexity can be calculated by using Control
Flow Graphs
▪ Independent path is defined as a path that has at least one
edge which has not been traversed before in any other
paths
Types of testing (WB)
31
Mona Ismail
Spring 2022
How to Calculate
Cyclomatic Complexity ?
It can be calculated using McCabe’s Cyclomatic
▪ McCabe's cyclomatic matric: it is set of independent paths
through the graph diagram. The Code complexity of the
program can be defined as:
V(G) = E - N + 2
Where,
E – Number of edges
N – Number of Nodes
32
Types of testing (WB)
Mona Ismail
Spring 2022
How to Calculate
Cyclomatic Complexity ?
Another way to calculated Cyclomatic
▪ Determine number of bounded areas in the graph
V(G) = Total number of bounded areas + 1
Bounded area: any region enclosed by a nodes and edge
sequence
Types of testing (WB)
Mona Ismail
33
Spring 2022
int f1(int x, int y){
1 while (x != y){
2 if (x>y) then
x=x-y;
3
4 else y=y-x;
5 }
}
6 return x;
1
Using McCabe's cyclomatic:
V(G) = E - N + 2 = 7- 6 + 2 = 3
2
3
4
5
6
The number of bounded
areas is 2
Using Bounded Area:
V(G) = Total number of
bounded areas + 1
=2+1=3
Number of independent paths: 3
▪ 1,6
→
test case (x=1, y=1)
▪ 1,2,3,5,1,6
→
test case(x=2, y=1)
▪ 1,2,4,5,1,6
→
test case(x=2, y=4)
Types of testing (WB)
Mona Ismail
Spring 2022
34
A
if (B) C
For Path coverage, it should cover all
the independent paths
Run 1:
B = false F = false
# executes A B _ D E F _ I
E
Run 2:
Path coverage implies
B = false F = true
if (F) G
branch coverage
# executes A B _ D E F G I
I
Run 3:
B = true F = false
For branch coverage, both B
# executes A B C _ E F _ I
and F would have to each
Run 4:
Run 1:
be false and true each
B = true F = true
B = false
# executes A B C _ E F G I
F = false
# executes A B _ D E F _ I
Run 2:
B = true
F = true
Types of testing (WB)
Mona Ismail
Spring 2022
# executes A B C _ E F G I
else D
35
A
For Path coverage, it should cover all
if (B) C
the independent paths
else D
Run 1:
E
B = false F = false
# executes A B _ D E F _ I
if (F) G
Run 2:
I
B = false F = true
# executes A B _ D E F G I
Run 3:
B = true F = false
Path coverage implies
# executes A B C _ E F _ I
branch coverage
Run 4:
B = true F = true
# executes A B C _ E F G I
Types of testing (WB)
Mona Ismail
36
Spring 2022
▪ When the CFG has loops, there are in general infinitely
many possible paths
▪ In some cases, the number of loop iterations is bounded by
a constant and can be tested, but in general this is not the
case
▪ Since complete path coverage is useful but not reachable,
we tend to use other coverage metrics
Types of testing (WB)
Mona Ismail
37
Spring 2022
Download