STQA Lecture Slides 04
STQA Lecture Slides 04
2
Introduction
3
Function, 1/4
4
Function, 2/4
5
Function, 3/4
6
Function, 4/4
7
Key Elements of a Function
• Three key elements of a function are its input, output, and expected
transformation of input to output
• Ignoring the details of the actual transformation of input to output, we
analyze the domains of the input and the output variables of programs to
generate test data
8
Key Concepts in Functional Testing
9
Types of Variables
10
Numeric Variable
11
12
Input, Output
13
Input
14
Output
15
Selection Criteria, 1/2
16
Selection Criteria, 2/2
• A dual-use variable is one that holds an input to the system under test at the
beginning of system execution and receives an output value from the
system at some point thereafter
• A multiple-type variable is one that can hold input (or even output) values of
different types, such as numeric and string, at different times
17
Selection Criteria for Input Variables, 1/3
18
Selection Criteria for Input Variables, 2/3
19
Selection Criteria for Input Variables, 3/3
20
Selection Criteria for Output Variables, 1/3
21
Selection Criteria for Output Variables, 2/3
• The output variable of the frequency hopping box has a domain of two
discrete sets {0, . . . , 22} and {0, . . . , 78} for MODE = 23 and MODE = 79,
respectively
• The frequency hopping box must be adequately tested so that it produces
each of the output values as desired
• For a large set of discrete values, the program is tested with many different
inputs that cause the program to produce many different output values
22
Selection Criteria for Output Variables, 3/3
25
Array
• An array holds values of the same type, such as integer and real
• Individual elements of an array are accessed by using one or more indices
• In some programming languages, such as MATLAB, an array can hold values
of both integer and real types
26
Array Properties
• Array can have one or more dimensions … to control loops, max. min., etc.
• Individual array elements are considered as distinct numeric variables
• Portion of an array can be collectively interpreted as a distinct substructure
with specific application-dependent properties … diagonal, upper triangular,
lower triangular, etc.
27
Substructure
• In general, a structure means a data type that can hold multiple data elements
• In the field of numerical analysis, a matrix structure is commonly used
• For example, a set of n linear equations in n unknown quantities is represented
by an n × (n + 1) matrix
• The n rows and the first n columns of the matrix represent the coefficients of
the n linear equations, whereas the (n + 1)th column represents the constants of
the n equations
28
Subroutine Arguments, 1/2
• Some programs accept input variables whose values are the names of
functions
• Such programs are found in numerical analysis and statistical applications
• Functional testing requires that each value of such a variable be included in
a test case
29
Subroutine Arguments, 2/2
• A test vector, also called test data, is an instance of the input to a program
• It is a certain configuration of the values of all the input variables
• Values of individual input variables chosen must be combined to obtain a
test vector
31
Test Vector, 2/3
• If a program has n input variables var1, var2, . . . , varn which can take on k1,
k2, . . ., kn special values, respectively, then there are k1 × k2 × · · · × kn
possible combinations of test data
• For module, if k1 = 2 for MODE, k2 = 3 for CLOCK, and k3 = 3 for ADDRESS;
then possible combinations of test data = 2 x 3 x 3 = 18
32
Test Vector, 3/3
33
Need to Reduce Number of Test Vectors
35
Identifying Functionally Related Variables
36
Reducing Number of Test Vectors through
Identifying Functionally Related Variables
37
38
39
Testing a Function in Context, 1/4
40
Testing a Function in Context, 2/4
41
Testing a Function in Context, 3/4
• If we are unaware of the predicate x ≥ 20, then we are likely to select the
following set of test data to test P: x = +k, x = −k, x = 0; k is a number with a
large magnitude
• Function f will be invoked just once for x = +k, assuming that k ≥ 20, and it
will not be invoked when P is run with the other two test data
• Testing function f in isolation vs. testing function f in context
42
Testing a Function in Context, 4/4
• Two data points (x = −k and x = 0) are invalid data as they fall outside the range of x for f in P
• Valid range of x for f is [20, +∞], and functional testing in context requires us to select the
following values of x:
x = k where k ≫ 20
x = y where 20 < y ≪ k
x = 20
where the symbols ≪ and ≫ are read as “much larger” and “much smaller,” respectively.
43
Functional Testing Main Points
• Identify the input and the output variables of the program and their data
domains
• Compute the expected outcomes as illustrated in Figure 9.5a for selected
input values
• Determine the input values that will cause the program to produce selected
outputs as illustrated in Figure 9.5b
44
45
Generating Test Data by Analyzing Input
Domain
• The number of test cases obtained from an analysis of the input domains is
likely to be too many because of the need to design test vectors
representing different combinations of special values of the input variables.
• Generation of expected output for a certain test vector is relatively simple
• This is because a test designer computes an expected output from an
understanding and analysis of the specification of the system
46
Generating Test Data by Analyzing Output
Domain
• The number of test cases obtained from an analysis of the output domains is
likely to be fewer compared to the same number of input variables because
there is no need to consider different combinations of special values of the
output variables.
• Generating an input vector required to produce a chosen output value will
require us to analyze the specification in the reverse direction
• Reverse analysis will be a more challenging task than computing an expected
value in the forward direction
47
Functional Testing at the Computing Element
Level
• We have discussed the ways to apply the idea of functional testing to an entire
program
• However, the underlying concept, that is, analyzing the input and output
domains of a program, can as well be applied to individual modules, functions,
or even lines of code aka code block
• This is because every computing element can be described in terms of its
input and output domains, and hence the idea of functional testing can be
applied to such a computing element
48
Example
49
50
51
Developing Functional Test Cases
• Methodology for developing functional test cases is an analytical process that decomposes
specification of a program into different classes of behaviors
• Functional test cases are designed for each class separately by identifying the input and
output domains of the class
• Identification of input and output domains help in classifying the specification into different
classes
• However, often, in practice, the total number of input and output combinations can be very
large
• Several well-known techniques are available to tackle this issue
52
Functional Testing Techniques
• Pairwise Testing
• Equivalence Class Testing
• Boundary Value Analysis
• Decision Tables
• Random Testing
• Error Guessing
• Category Partition
53