Class 16
Class 16
1
How Do You Test a
Program?
● Input test data to the
program.
● Observe the output:
– Checkif the program
behaved as expected.
2
Error, Faults, and
Failures
● A fault is an incorrect state
entered during program
execution:
– A variable value is different from
what it should be.
– A fault may or may not not lead
to a failure.
3
Verification versus
Validation
● Verification is the process of
determining:
– Whether output of one phase of
development conforms to its previous
phase.
5
Test cases and Test
suites
● A test case is a triplet [I,S,O]
– I is the data to be input to the
system,
– S is the state of the system at
which the data will be input,
– O is the expected output of the
system.
6
Design of Test Cases
● Exhaustive testing of any non-
trivial system is impractical:
– Input data domain is extremely large.
7
Design of Test Cases
● If test cases are selected randomly:
– Many test cases would not contribute to
the significance of the test suite,
– Would not detect errors not already being
detected by other test cases in the suite.
● Number of test cases in a randomly
selected test suite:
– Not an indication of effectiveness of
testing.
8
Design of Test Cases
● The code has a simple programming error:
● If (x>y) max = x;
else max = x;
● Test suite {(x=3,y=2);(x=2,y=3)} can
detect the error,
● A larger test suite {(x=3,y=2);(x=4,y=3);
(x=5,y=1)} does not detect the error.
9
Design of Test Cases
● There are essentially two
main approaches to design
test cases:
– Black-box approach
– White-box (or glass-box)
approach
10
Black-Box Testing
● Test cases are designed using only
functional specification of the
software:
– Without any knowledge of the
internal structure of the software.
● For this reason, black-box testing
is also known as functional
testing.
11
White-box Testing
12
Black-Box Testing
● There are essentially two
main approaches to design
black box test cases:
– Equivalence class partitioning
– Boundary value analysis
13
Equivalence Class
Partitioning
● Input values to a program are
partitioned into equivalence
classes.
● Partitioning is done such that:
– Program behaves in similar ways
to every input value belonging to
an equivalence class.
14
Equivalence Class
Partitioning
● How do you determine the
equivalence classes?
– Examine the input data.
– Few general guidelines for
determining the equivalence
classes can be given
15
Equivalence Class
Partitioning
● If the input data to the program is
specified by a range of values:
– e.g. numbers between 1 to 5000.
– One valid and two invalid equivalence
classes are defined.
1 5000
16
Example
● A program reads an input value
in the range of 1 and 5000:
– Computes the square root of the
input number
SQR
T
17
Example (cont.)
● There are three equivalence classes:
– The set of negative integers,
1 5000
18
Example (cont.)
1 5000
19
Equivalence Class Partitioning
● If input is an enumerated set of
values:
– e.g. {a,b,c}
– One equivalence class for valid input
values.
– Another equivalence class for invalid input
values should be defined.
20
Boundary Value Analysis
● Some typical programming errors occur:
– At boundaries of equivalence classes
21
Boundary Value Analysis
● Programmers may improperly
use < instead of <=
● Boundary value analysis:
– Select test cases at the
boundaries of different
equivalence classes.
22
Example
● For a function that computes
the square root of an integer in
the range of 1 and 5000:
– Test cases must include the
values: {0,1,5000,5001}.
1 5000
23
Thanks
24