07-Requirements-based-Functional-Testing-one-slide
07-Requirements-based-Functional-Testing-one-slide
for
Functional Testing
W. Eric Wong
Department of Computer Science
The University of Texas at Dallas
ewong@utdallas.edu
http://www.utdallas.edu/~ewong
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 1
Speaker Biographical Sketch
Professor & Director of International Outreach
Department of Computer Science
University of Texas at Dallas
Guest Researcher
Computer Security Division
National Institute of Standards and Technology (NIST)
Vice President, IEEE Reliability Society
Secretary, ACM SIGAPP (Special Interest Group on Applied Computing)
Principal Investigator, NSF TUES (Transforming Undergraduate Education in
Science, Technology, Engineering and Mathematics) Project
– Incorporating Software Testing into Multiple Computer Science and Software
Engineering Undergraduate Courses
Founder & Steering Committee co-Chair for the SERE conference
(IEEE International Conference on Software Security and Reliability)
(http://paris.utdallas.edu/sere13)
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 2
Two Techniques for Test Generation
Equivalence Class partitioning Essential black-box techniques for
generating tests for functional
Boundary value analysis
testing
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 3
Functional Testing
Testing a program/sub-program to determine whether it functions as
planned
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 4
Equivalence Class Partitioning
5
Example I (1)
Consider an application that takes an integer as input
Let us suppose that the only legal values are in the range [1..100]
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 6
Example I (2)
The set of input values can be divided into
– A set of expected, or legal, inputs (E) containing all integers in the
range [1..100]
– A set of unexpected, or illegal, inputs (U ) containing the remaining
integers
All integers
U: Other integers
E: [1..100]
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 7
Example I (3)
Assume that the application is required to process all values in the range
[1..50] in accordance with requirement R1 and those in the range
[51..100] according to requirement R2.
– E is divided into two regions depending on the expected behavior.
Also assume that all invalid inputs less than 1 are to be treated in one
way while all greater than 100 are to be treated differently.
– This leads to a subdivision of U into two categories.
All integers
<1
[51..100] >100
[1..50]
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 8
Example I (4)
the application ?
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 9
Equivalence Partitioning
Test selection using equivalence partitioning allows a tester to
divide the input domain into a relatively small number of sub-
domains.
The sub-domains are disjoint.
Each subset is known as an equivalence class.
The four subsets shown in (a) constitute a partition of the input
domain while the subsets in (b) are not.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 10
Quiz
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 11
Unidimensional Partitioning
One way to partition the input domain is to consider one input
variable at a time. Thus each input variable leads to a partition of
the input domain.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 12
Multidimensional Partitioning
Another way is to consider the input domain I as the set product of
the input variables and define a relation on I. This procedure
creates one partition consisting of several equivalence classes.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 13
Example II (1)
Consider an application that requires two integer inputs x and y.
Each of these inputs is expected to lie in the following ranges: 3≤
x≤7 and 5≤y≤9.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 14
Example II (2)
Using Unidimensional Partitioning
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 15
Example II (3)
Using Multidimensional Partitioning
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 16
Example II (4)
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 17
Equivalence Classes based on Program Output (1)
In some cases the equivalence classes are based on the output generated
by the program.
It is worth asking: “Does the program ever generate a 0? What are the
maximum and minimum possible values of the output?”
These two questions lead to two the following equivalence classes based
on outputs:
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 18
Equivalence Classes based on Program Output (2)
E1: Output value v is 0
E2: Output value v is the maximum possible
E3: Output value v is the minimum possible
E4: All other output values
Based on the output equivalence classes one may now derive equivalence
classes for the inputs. Thus each of the four classes given above might
lead to one equivalence class consisting of inputs.
More examples . . . . . . . . .
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 19
Equivalence Classes for variables : Range
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 20
Equivalence Classes for variables : String
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 21
Equivalence Classes for variables : Enumeration
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 22
Equivalence Classes for variables : Array
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 23
Equivalence Classes for Compound Data Type (1)
Arrays in Java and structures in C++/C, are compound types. Such input
types may arise while testing components of an application such as a
function or an object.
While generating equivalence classes for such inputs, one must consider
legal and illegal values for each component of the structure.
The next two examples illustrate the derivation of equivalence classes for
an input variable that has a compound type.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 24
Equivalence Classes for Compound Data Type (2)
struct transcript
{
string fName; // First name
string lName; // Last name
string studentID // 9 digits
string cTitle [200]; // Course titles
char grades [200]; // Letter grades corresponding to course titles
}
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 25
Equivalence Classes for Compound Data Type (3)
Consider a procedure P in a payroll processing system that takes an
employee record as input and computes the weekly salary. For simplicity,
assume that the employee record consists of the following items with
their respective types and constraints:
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 26
Systematic Procedure for Equivalence Partitioning
1. Identify the input domain: Read the requirements carefully and identify
all input and output variables, their types, and any conditions associated
with their use.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 27
Example III (1)
Consider that wordcount method takes a word w and a filename f as
input and returns the number of occurrences of w in the text contained in
the file named f. An exception is raised if there is no file with name f.
Using the partitioning method described in the previous example, we
obtain the following equivalence classes.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 28
Example III (2)
Equivalence class w f
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 29
Example III (3)
The number of equivalence classes without any knowledge of the
program code is 2, whereas the number of equivalence classes on the
previous slide is 6.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 30
Quiz
How many equivalence classes do we need for the wordcount program?
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 31
GUI Design and Equivalence Classes (1)
While designing equivalence classes for programs that obtain input
exclusively from a keyboard, one must account for the possibility of
errors in data entry.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 32
GUI Design and Equivalence Classes (2)
Suppose that all data entry to the application is via a GUI front end.
Suppose also that the GUI offers exactly five correct choices to the user
for x.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 33
GUI Design and Equivalence Classes (3)
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 34
Program Behavior and Equivalence Classes
The equivalence classes are created assuming that the program behaves
the same on all elements (i.e., tests) within a class.
This assumption allows the tester to select exactly one test case from each
equivalence class to test the program.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 35
Boundary Value Analysis
36
Errors at the Boundaries
Experience indicates that programmers make mistakes in processing
values at and near the boundaries of equivalence classes.
In this example, the value x=0, lies at the boundary of the equivalence
classes x≤0 and x>0.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 37
Equivalence Partitioning & Boundary Value Analysis
While equivalence partitioning selects tests from within equivalence
classes, boundary value analysis focuses on tests at and near the
boundaries of equivalence classes.
Certainly, tests derived using either of the two techniques may overlap.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 38
Boundary Value Analysis : Procedures
Partition the input domain using unidimensional partitioning. Alternately,
a single partition of an input domain can be created using
multidimensional partitioning. We will generate several sub-domains in
this step.
Select test data such that each boundary value occurs in at least one test
input.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 39
BVA Example : Step 1 – Create Equivalence Classes
Assuming that a program takes two variables as input: code must be in
the range 99..999 and quantity in the range 1..100
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 40
BVA Example : Step 2 – Identify Boundaries
Boundaries are indicated with an x.
0 2 99 101
* x * * x *
1 * 100 *
E4 E5 E6
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 41
BVA Example : Step 3 – Construct Test Set
Test selection based on the boundary value analysis technique requires
that tests must include, for each variable, values at and around the
boundary.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 42
Equivalence Class Partitioning
versus
Statement Coverage
43
Example: Identify the Type of a Triangle (1)
A program P takes an input of three integers a, b and c, and returns the
type of the triangle corresponding to three sides of length a, b, and c,
respectively.
Quiz:
– How to generate a test set based on Equivalence Class Partitioning
to achieve the highest statement coverage possible?
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 44
Example: Identify the Type of a Triangle (2)
Question:
What is the statement coverage of your test set?
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 45
Boundary Value Analysis
Versus
Decision Coverage
46
Complement between BVA and Decision Coverage
Test cases generated based on Boundary Value Analysis improve decision
coverage.
Similarly, test cases that achieve high decision coverage also cover some
boundary values.
Examples
– If (x ≤ 0) {…..}
BVA: {x1 = 0; x2 = 1; x3 = –1}
Together, x1, x2 and x3 give 100% decision coverage.
– If (y = = 3) {…..}
{y1 = 3 and y2 = a value different from 3} gives 100% decision coverage.
At least one of the boundary value (y = 3) is covered.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 47