0% found this document useful (0 votes)
138 views62 pages

9.white Box Testing

Uploaded by

Sandy Cyrus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views62 pages

9.white Box Testing

Uploaded by

Sandy Cyrus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 62

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.

• Depends on environment and inputs.


• How well do we know the environment?
• How much control do we have over test inputs?
Outline
■ Testing Types
■ Testing Techniques
■ White-box Testing
■ Black-box Testing
Test Strategies and Techniques 1
• Test Strategy
– Outlines in broad terms how to use testing to
assess the extent to which the goal for a prod
uct has been met.
• Test Techniques
– Implement strategies, provide the data neede
d to do the assessment.
Test Strategies and Techniques 2
• Both strategy and techniques guide how te
st cases are chosen.

• Distinction between strategy and techniqu


e is soft.
Testing Techniques
• There are two testing techniques:
1. Test to code
– Also called glass-box, logic-driven, structure
d, or path-oriented testing.
2. Test to specifications
– Also called black-box, data-driven, functional,
or input/output driven testing
White-box Testing
• Ignore the specifications — use the cod
e to derive the test cases.
• Objective is to exercise all program state
ments.
(not all path combinations)
White Box Testing
• Internal structure
– Paths
– Logical conditions
– Loops
– Data structures
White Box Testing contd.
• Guarantees execution of all independent
paths
• Exercises all logical decisions
• Executes all loops at their boundaries
• Verifies validity of internal data structures
White Box Testing-
Methodologies
• Basis Path
• Control Structure
• Mutation
White Box Testing-
Methodologies
• Basis Path
• Control Structure
• Mutation
White-box Testing Techniques

• Basis Path Testing


• Condition Testing
• Data Flow Testing
• Loop Testing Variants of Basis
Path Testing
Basis Path Testing
• Is a white-box testing technique, proposed by
Tom McCabe.
• Procedure
1. Draw the flow graph of the candidate procedur
al design.
2. Calculate the complexity measure of the flow g
raph.
3. Define a basis set of execution paths.
4. Derive a test case against each path.
Basis Path
• Uses logical complexity
• Helps adding necessary test
• Excludes redundant tests
• Identify important paths
Basis Path-
Control Flow Graphs
• Translation of source code
• Consists of
– Node
– Edges
– Regions
– Predicate Node

sequence if while until case


Flow Graph
• A Flow Graph is similar to a flowchart.
• Describes the program control flow.
• Node represents one or more than one stateme
nt.
• Edges represents the flow of control.
• A node is called a predicate node if it contains a
condition.
• A linear sequence of nodes can be combined int
o one node.
Basis Path-
Control Flow Graphs contd.
1. pos_sum(a, num_of_entries, sum)
2. sum = 0
3. Int i = 1
4. while (i < num_of_entries)
5. if a[i] > 0
6. Sum = sum + a[i]
endif
7. i=i+1
end while
8. end pos_sum
Basis Path-
Control Flow Graphs contd.
Basis Path-
Cyclomatic Complexity
• A software metric
– Quantitatively measures the complexity of pro
gram
• Minimum number of tests
Basis Path-
Cyclomatic Complexity contd.
• How to calculate
– Number of regions
– Edges – Nodes + 2
– Predicate Nodes + 1
– Graph Matrices
• Basis/Independent paths
– 1-2-3-4-8
– 1-2-3-4-5-6-7-4-8
– 1-2-3-4-5-7-4-8
• Basis Set
Basis Path-
Cyclomatic Complexity contd.
1 2, 3 4 5 6 7 8

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

Draw a flow chart for


Given program.
Flow Graph: Example 2

Flow chart
Flow Chart => Flow Graph
Cyclomatic Complexity 1

• Cyclomatic complexity provides the quantitativ


e measure of the logical complexity of a progra
m.
• It defines the number of independent paths in t
he basis set of a program.
• Any path through the program that introduces
at least one new set of processing statements
or condition variables is called an independent
path.
• This is an upper bound to the number of test c
ases for that program.
Cyclomatic Complexity 2

• Cyclomatic complexity V(G) can be calcu


lated from the flow graph as:

• 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

• Hence, Cyclomatic Complexity = 4, means th


ere are four independent paths. Lets find out!
Independent paths 1

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

• Not practical for large n


• For n variables, the scenarios will be 2n
BRO-
Branch & Relational Operator
• Condition Constraints
– Possible outcomes
– Boolean
• TRUE
• FALSE
– Relational
•>
•<
•=
BRO contd.
• Example
– B1 & (E1 = E2)
– (E1 = E2) & (E3 = E4)
BRO contd.
• Lower number of cases
– Less than 2n
• Good for larger value of n
Control Structure
• Condition
• Data Flow
• Loops
Data Flow
• Data definition
– Value of a variable is assigned or changed
• Data usage
– Value of a variable is utilized
– Predicate use p-use
• if (X > 98)
– Computation use c-use
• Y = 26 * X
• Definition use path def-use
Data Flow-
Example
Data Flow-
Example contd.
n number

def use def use

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

You might also like