Professional Documents
Culture Documents
Overview
It depends on metrics
Control flow testing
Coverage testing-uses coverage metrics
Basis path testing-uses complexity metrics
Boundary values and equivalence classes
Data flow testing
Quality Assurance and Software Testing
White box testing
Disadvantages
double r a t i o ( i n t a , i n t b) {
r e t u r n ( a /b ) ;
}
a=a+1 // a c t u a l b u t i n c o r r e c t c o d e
a=a−1 ; // c o r r e c t c o d e
Quality Assurance and Software Testing
White box testing
Nodes= statements/fragments
Edges show the flow of control
Decision points
Junction points
Only one entry at the beginning
of graph
Only one exit at the end
Quality Assurance and Software Testing
White box testing
Example
i f ( a>0)
x=x +1;
i f ( b==3)
y =0;
Quality Assurance and Software Testing
White box testing
Testing metrics
Coverage
Levels of coverage
Level 0. Test whatever you test. Let the users test the rest:
irresponsible
Level 1. 100% statement coverage = during testing the flow
of control reached each executable line of code at least one.
Quality Assurance and Software Testing
White box testing
Level 1
Test cases are created for each condition and each decision
Test cases
x=2 y=11
x=2 y=9
x=0 y=11
x=0 y=9
Quality Assurance and Software Testing
White box testing
McCabe complexity
C = e-n+2
e = nr. of edges
n=number of nodes
Quality Assurance and Software Testing
White box testing
Example
Quality Assurance and Software Testing
White box testing
Unit testing
Assertions
JUnit Assertions
Assertions
assertEquals(expected, actual)
assertEquals(expected, actual, delta) for floats Ex:
assertEquals(3.33, 10.0/3.0, 0.01)
assertEquals(message,expected,actual)
assertTrue(condition)
Can be found in JUnit API
Quality Assurance and Software Testing
White box testing
A simple example
Assertions
public class Calculator {
p u b l i c s t a t i c i n t add ( i n t a , i n t b ){
r e t u r n ( a+b ) ;
}
}
Coverage analysis
Annotations
Example
For variable x :
def in 1 and 4
c-use in 4
p-use in 5
DU paths:
1 − 2 − 3 − 5 and
1−2−4
Quality Assurance and Software Testing
White box testing
All-defs
All DU pairs (All c-uses All p-uses)
All DU paths
Quality Assurance and Software Testing
White box testing
All-defs coverage
All p-uses
Ensures that if a variable is defined and later used within a
conditional expression, this def-use pair is executed at least once
causing the surrounding decision to evaluate true, and once
causing the decision to evaluate false
All c-uses
Ensures that if a variable is defined and used later, at least one
definition clear path between these 2 events will be executed.
Quality Assurance and Software Testing
White box testing
All DU pairs
All DU-paths
Test coverage
Test coverage criteria hierarchy (control flow and data flow based)
Quality Assurance and Software Testing
White box testing
Mutation testing
Fault injection
Quality Assurance and Software Testing
White box testing
The procedure
Simple faults are introduced into the SUT by creating a set of
faulty versions, named mutants. Each mutant has a small
change and is created by a mutation operator, described by
syntactic changes.
The test set is run on the mutants and the result is compared
with the original results
From this comparison the tester draws conclusions and
improves his testing- indirectly mutation testing is a method
to design test cases
Quality Assurance and Software Testing
White box testing
Mutation testing
Select mutation operators
Generate mutants
Distinguish mutants
Quality Assurance and Software Testing
White box testing
Mutation operators
Example
AOR- arithmetic operator replacement Applied to an assignment
statement result = a + b Yields 4 mutants:
result=ab
result =ab
result=ab
result=a%b
Quality Assurance and Software Testing
White box testing
Equivalent mutant
Equivalent mutant differs syntactically, but semantically is
the same with the original program
A problem for mutation testing because and it can never be
killed
Open research question: detecting equivalent mutants
Quality Assurance and Software Testing
White box testing
Procedure
Equivalent mutant
Test set run on the mutant gives another output, fault is
detected, the mutant is declared killed by the test.
The output is the same: it can be that the mutant is
equivalent. If it is not, then the mutant is declared alive. The
test case failed to detect the fault – it is ineffective and new
test cases have to be designed.
In this way, mutation testing helps tester to start a new
iteration and improve his testing.
Quality Assurance and Software Testing
White box testing
Original A mutant
y =2; y =2;
x=y ∗ 2 ; x=y ∗ 4 ;
i f ( x<z ) i f ( x<z )
x =1; x =1;
e l s e i f ( x==z ) e l s e i f ( x==z )
x =0; x =0;
e l s e x=x +1; e l s e x=x +1;
p r i n t f ( ”%d” , x ) ; p r i n t f ( ”%d” , x ) ;
Mutation score
Equivalent mutant
Given a SUT and a test case set, the method returns a value,
called mutation score (MS)
MS=(#killed mutants/total-#equivalent mutants)x100%
Test is mutation adequate if the mutation score is 100%
Quality Assurance and Software Testing
White box testing
Practice
Mutation tools
MuClipse
Fault injection
Fault injection
Problems
The injected fault has to be representative of software faults
observed in the field
Characterization and classification of faults (defects) is an
essential step in fault injection
The time issue