Professional Documents
Culture Documents
9.white Box Testing
9.white Box Testing
Outline
■ Testing Types
■ Testing Techniques
■ White-box Testing
■ Black-box Testing
Outline
■ Testing Types
■ Testing Techniques
■ White-box Testing
■ Black-box Testing
Testing Types
• There are two types of testing:
1. Non-execution-based Testing
2. Execution-based Testing
Non-execution-based Testing
• A document is checked by a team of software
professionals with a range of skills.
• Increases chances of finding a fault.
• Types of Non-execution-based Testing
– Walkthroughs
– Inspections
Execution-based Testing
• Execution-based testing is a process of inferri
ng certain behavioral properties of a product,
based, in part, on the results of executing the
product in a known environment with selecte
d inputs.
1, 2, 3 1 1–1=0
4 1 1 2–1=1
5 1 1 2–1=1
6 1 1–1=0
7 1 1–1=0
8
CC = 2 + 1
Flow Graph: Example 1
Flow chart
Flow Chart => Flow Graph
Cyclomatic Complexity 1
• V(G) = R
• V(G) = E – N + 2
• V(G) = P + 1
• Where R = No. of regions, E = No. of edges, N = No. of nodes, P
= No. of predicate nodes.
Cyclomatic Complexity: Example 1
Cyclomatic Complexity: Example 2
• Here
– R = 4 => V(G) = 4
– E = 11, N = 9 => V(G) = 11-9+2 = 4
– P = 3 => V(G) = 3+1 = 4
path 1: 1-11
Independent paths 2
• path 1: 1-11
• path 2: 1-2-3-4-5-10-1-11
Independent paths 3
• 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
Independent paths 4
• 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
Exercise 1.
Draw the flow graph, calculate the cyclomatic complexity, list the basis paths
and prepare a test case for one path using the following code segment:
Read (a);
Read (b);
if a>b then
print a;
else if a<b then
print b;
else
print “Equal-Equal”;
end if
Exercise 2.
Draw the flow graph, calculate the cyclomatic complexity, list the basis paths
and prepare a test case for one path using the following code segment:
Void perform_word_count()
{
string ValidatedFileName;
int WordCount;
if ( get_input(ValidatedFileName) is false )
print “error 1: file does not exist”
else
set WordCount equal to count_number_of_words(ValidatedFileName);
if (WordCount is equal to –1 )
print “error 2: file is not text file”
else
produce_output(WordCount);
}
Control Structure
• Condition
• Data Flow
• Loops
Condition Testing
• Exercises logical conditions
• Errors found include
– Boolean operator error (OR, AND, NOT)
– Boolean variable error
– Relational operator error (>,<,=,!=)
Condition Testing Strategies
• Branch Testing
• Domain Testing
• BRO-Branch & Relational Operator
Condition Testing Strategies-
Branch Testing
• Condition can only be
– TRUE
– FALSE
• Example
–B>A
–A=D
Condition Testing Strategies-
Branch Testing contd.
• Good for
– Boolean variables
– Simple Expressions
• Fails for compound/complex conditions
– A & (B || (s))
Condition Testing Strategies-
Domain Testing
• Complex/compound conditions
– A & (B || (C & D))
• All possible outcomes of all variables
Condition Testing Strategies-
Domain Testing contd.
• Good coverage
1 2 4 1 5 6
i sum
def use def use
1 3 4 1 1 6
2 3 7 2 1 9
3 7 7 3 6 6
4 7 4 4 6 9
Control Structure
• Condition
• Data Flow
• Loops
Loop
• Types
– Simple
– Nested
– Concatenated
– Unstructured
Loops-
Simple
• With n number of pass
es, iterate:
– Zero pass
– One pass
– Two passes
– m passes where m < n
– n – 1, n, n + 1
Loops-
Nested
• Begin with innermost k
eeping all other at mini
mal
• Conduct Simple loop tes
t for the one being teste
d
• Work outward with sam
e strategy
Loops-
Concatenated
• Independent
– Simple loop strategy
• Concatenated
– Nested loop strategy
Loops-
Unstructured
• Non testable
• Repetition
• Strategy
– Avoid
– Redesign
White Box Testing-
Methodologies
• Basis Path
• Control Structure
• Mutation
Mutation Testing
• A fault-based testing approach
– Mutants
• Mutant Killed
– Results are different from the original
• Mutant Equivalent
– Results are same as the original
Mutation Testing contd.
• Code modifications
– Constant replacement
– Arithmetic operator replacement
– Data statement alteration
– Statement deletion
– Logical operator replacement
Mutation Testing-
Example
• Mutant Killed
– Replace i = i + 1 with i = i
+2
– Replace If (a > 0) with If
(a < 0)
• Mutant Equivalent
– Replace if a[i] > 0 with if
a[i] >= 0
– Test Data Set
– A = 0, 1, 2