Testing Techniques
Testing Techniques
1
Software Testing Techniques
• Black Box Testing
• White Box Testing
2
Black Box Testing
Knowing specified function that a product has been designed
to perform, tests can be conducted that demonstrate each
function is fully operational while at the same time searching
for errors in each function.
3
Black Box
Testing
Focus on interfaces
4
White-Box
Testing
6
White-Box Testing
Cyclomatic Complexity:
It is a software metric that provides a quantitative measure
of the logical complexity of a program
7
White-Box Testing
Cyclomatic Complexity
or
or
8
Example
while(value[i] != -999.0 && totinputs < 100)
{ totinputs++;
if(value[i] >= min && value[i] <= max)
{ totvalid++;
sum = sum + value[i];
}
i++;
}
9
1 2
while(value[i] != -999.0 && totinputs < 100)
{ totinputs++;
3 4
if(value[i] >= min && value[i] <= max)
{ totvalid++;
i++; 6
}
7
10
Cyclomatic Complexity:
V(G) = number of enclosed areas + 1 = 5
V(G) = number of simple predicates + 1 = 5
V(G) = edges - nodes + 2 = 10 - 7 + 2 = 5
11
Cyclomatic Complexity by Graph Matrix
1 2 3 4 5 6 7 Calculations
1 x x =2 = 2-1 = 1
2 x x =2 = 2-1 = 1
3 x x =2 = 2-1 = 1
4 x x =2 = 2-1 = 1
5 x =1 = 1-1 = 0
6 x =1 = 1-1 = 0
7 --- ---
Cyclomatic Complexity = 4 + 1 = 5
12
Independent Paths:
1.1-7 (value[i] = -999.0)
2.1-2-7 (value[i] = 0, totinputs = 100)
3.1-2-3-6-1-7
4.1-2-3-4-6-1-7
5.1-2-3-4-5-6-1-7
13
Black-Box Testing
Focus on:
Functional Requirements of the software i.e. Inputs, Outputs
Structure of program is not considered
14
Black-Box Testing
requirements
output
input events
15
Black-Box Testing
Equivalence Partitioning:
Three behaviors:
1. valid in put i.e. count within range
2. upper bound (Invalid)
3. lower bound (Invalid)
17
Black-Box Testing
Boundary Value Analysis:
It is observed that programs that work correctly for a set of values in an equivalence
class, fail on some special values i.e. on boundaries.
We choose an input from equivalence classes that lies on the edge of class
18
Black-Box Testing
19
Practice Quiz
void fib (int x)
{
int a=0,b=1,sum=0;
for(int i=1;i<=x;i++)
{
sum=a+b;
cout<<sum<<"\t";
a=b;
b=sum;
}
}
20
Solution
Cyclomatic Complexity:
Number of regions = 2
Number of predicates = 1+1 = 2
Edges – Nodes + 2 = 5 – 5 + 2 = 2
1 2 3 4 5
21
Sample Quiz
#include <stdio.h>
int main()
{
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
while (n != 0)
{
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.",
original);
return 0;
}
22
4
1 2 3 6
Cyclomatic Complexity:
Number of regions = 3
Number of predicates = 2+1 = 3
Edges – Nodes + 2 = 7 – 6 + 2 = 3
23
Practice Question
Public boolean find(int key)
{ int bootom = 0; int top = elements.length-1; int last index = (bottom + top)/2; int mid;
boolean found = key == elements [lastIndex];
while ((bottom <= top) && !found )
{
mid = (bottom + top) / 2;
found = key == elements[mid];
if (found)
{
lastIndex = mid;
}
else
{
if (elements[mid] < key)
{
bottom = mid +1;
}
else
{
top = mid – 1;
}
}
}
24