Chapter 6
Equivalence Class Testing
6/28/2021 1
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Outline
• Motivation. Why bother?
• Equivalence Relations and their consequences
• “Traditional” Equivalence Class Testing
• Four Variations of Equivalence Class Testing
• Examples
6/28/2021 2
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Motivation
• In chapter 5, we saw that all four variations of boundary
value testing are vulnerable to
– gaps of untested functionality, and
– significant redundancy, that results in extra effort
• The mathematical notion of an equivalence class can
potentially help this because
– members of a class should be “treated the same” by a program
– equivalence classes form a partition of the input space
• Recall (from chapter 3) that a partition deals explicitly
with
– redundancy (elements of a partition are disjoint)
– gaps (the union of all partition elements is the full input space)
6/28/2021 3
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Motivation (continued)
• If you were testing the Triangle Program, would you use
these test cases?
– (3, 3, 3), (10, 10, 10), (187, 187, 187)
• In Chapter 5, the normal boundary value test cases
covered June 15 in five different years. Does this make
any sense?
• Equivalence class testing provides an elegant strategy to
resolve such awkward situations.
6/28/2021 4
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Equivalence Class Testing
Domain Range
Equivalence class testing uses information about the
functional mapping itself to identify test cases
6/28/2021 5
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Equivalence Relations
• Given a relation R defined on some set S, R is an equivalence
relation if (and only if), for all, x, y, and z elements of S:
– R is reflexive, i.e., xRx
– R is symmetric, i.e., if xRy, then yRx
– R is transitive, i.e., if xRy and yRz, then xRz
• An equivalence relation, R, induces a partition on the set S,
where a partition is a set of subsets of S such that:
– The intersection of any two subsets is empty, and
– The union of all the subsets is the original set S
• Note that the intersection property assures no redundancy, and
the union property assures no gaps.
6/28/2021 6
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Equivalence Partitioning
Domain Range
• Define a relation R on the input domain D as:
∀ x, y ϵ D, xRy iff F(x) = F(y), where F is the
program function.
• R is the “treated the same” relation
• Exercise: show that R is an equivalence
relation
6/28/2021 7
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Equivalence Partitioning (continued)
• Works best when F is a many-to-one
function
• Test cases are formed by selecting one value
from each equivalence class.
• Identifying the classes may be hard
6/28/2021 8
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Forms of Equivalence Class Testing
• “Traditional”—focus on invalid inputs
• Normal: classes of valid values of inputs
• Robust: classes of valid and invalid values of
inputs
• Weak: (single fault assumption) one from each
class
• Strong: (multiple fault assumption) one from each
class in Cartesian Product
• We compare these for a function of two variables,
F(x1, x2)
• Extension to problems with 3 or more variables is
“obvious”.
6/28/2021 9
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
“Traditional” Equivalence Class Testing
• Programmer arrogance:
– in the 1960s and 1970s, programmers often had very
detailed input data requirements.
– if input data didn’t comply, it was the user’s fault
– the popular phrase—Garbage In, Garbage Out (GIGO)
• Programs from this era soon developed defenses
– (many of these programs are STILL legacy software)
– as much as 75% of code verified input formats and
values
• “Traditional” equivalence class testing focuses on
detecting invalid input.
– (almost the same as our “weak robust equivalence class
testing”)
6/28/2021 10
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Continuing Example
• (only 2-dimensions for drawing purposes)
• easy to extend to more variables
• F(x1, x2) has these classes...
– valid values of x1: a ≤ x1 ≤ b
– invalid values of x1: x1 < a, b < x1
– valid values of x2: c ≤ x2 ≤ d
– invalid values of x2: x2 < c, d < x2
• Process
– test F for valid values of all variables,
– then test one invalid variable at a time
– (note this makes the single fault assumption)
6/28/2021 11
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Example
x2
Invalid values of x2
Valid values of x2
Invalid values of x2
x1
a b
Invalid values of x1 Valid values of x1 Invalid values of x1
6/28/2021 12
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Weak Normal Equivalence Class Testing
• Identify equivalence classes of valid values.
• Test cases have all valid values.
• Detects faults due to calculations with valid values
of a single variable.
• OK for regression testing.
• Need an expanded set of valid classes
– valid classes: {a <= x1 < b}, {b <= x1 < c}, {c <= x1 <= d},
{e <= x2 < f}, {f <= x2 <= g}
– invalid classes: {x1 < a}, {x1 > d}, {x2 < e}, {x2 > g}
6/28/2021 13
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Weak Normal Equivalence Class Test Cases
x2
x1
a b c d
6/28/2021 14
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Weak Robust Equivalence Class Testing
• Identify equivalence classes of valid and invalid values.
• Test cases have all valid values except one invalid value.
• Detects faults due to calculations with valid values of a
single variable.
• Detects faults due to invalid values of a single variable.
• OK for regression testing.
6/28/2021 15
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Weak Robust Equivalence Class Test Cases
x2
x1
a b c d
6/28/2021 16
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
x2
Is this g
preferable f
to this? Why?
e
x1
x2 a b c d
g
f
e
x1
a b c d
6/28/2021 17
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Strong Normal Equivalence Class Testing
• Identify equivalence classes of valid values.
• Test cases from Cartesian Product of valid values.
• Detects faults due to interactions with valid values of
any number of variables.
• OK for regression testing, better for progression
testing.
6/28/2021 18
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Strong Normal Equivalence Class Test Cases
x2
x1
a b c d
6/28/2021 19
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Strong Robust Equivalence Class Testing
• Identify equivalence classes of valid and invalid values.
• Test cases from Cartesian Product of all classes.
• Detects faults due to interactions with any values of any
number of variables.
• OK for regression testing, better for progression testing.
– (Most rigorous form of Equivalence Class testing, BUT,
– Jorgensen’s First Law of Software Engineering applies.)
• Jorgensen’s First Law of Software Engineering:
– The product of two big numbers is a really big number.
– (More elegant: scaling up can be problematic)
6/28/2021 20
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Strong Robust Equivalence Class Test Cases
x2
x1
a b c d
6/28/2021 21
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Selecting an Equivalence Relation
• There is no such thing as THE equivalence relation.
•If x and y are days, some possibilities for Nextdate are:
– xRy iff x and y are mapped onto the same year
– xRy iff x and y are mapped onto the same month
– xRy iff x and y are mapped onto the same date
– xRy iff x(day) and y(day) are “treated the same”
– xRy iff x(month) and y(month) are “treated the same”
– xRy iff x(year) and y(year) are “treated the same”
• Best practice is to select an equivalence relation that
reflects the behavior being tested.
6/28/2021 22
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
NextDate Equivalence Classes
• Month:
– M1 = { month : month has 30 days}
– M2 = { month : month has 31 days}
– M3 = { month : month is February}
• Day
– D1 = {day : 1 <= day <= 28}
– D2 = {day : day = 29 }
– D3 = {day : day = 30 }
– D4 = {day : day = 31 }
• Year (are these disjoint?)
– Y1 = {year : year = 2000}
– Y2 = {year : 1812 <= year <= 2012 AND (year ≠ 0 Mod 100)
and (year = 0 Mod 4)
– Y3 = {year : (1812 <= year <= 2012 AND (year ≠ 0 Mod 4)
6/28/2021 23
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Not Quite Right
• A better set of equivalence classes for year is
– Y1 = {century years divisible by 400} i.e., century leap years
– Y2 = {century years not divisible by 400} i.e., century
common years
– Y3 = {non-century years divisible by 4} i.e., ordinary leap
years
– Y4 = {non-century years not divisible by 4} i.e., ordinary
common years
• All years must be in range: 1812 <= year <= 2012
• Note that these equivalence classes are disjoint.
6/28/2021 24
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Weak Normal Equivalence Class Test Cases
Select test cases so that one element from each input domain equivalence
class is used as a test input value. The number of test cases is the same as
the highest number of equivalence classes for a variable.
Test Input Domain Input Values Expected Outputs
Case Equiv. Classes
WN-1 M1, D1, Y1 April 1 2000 April 2 2000
WN-2 M2, D2, Y2 January 29 1900 January 30 1900
WN-3 M3, D3, Y3 February 30 1842 Invalid date
WN-4 M1, D4, Y4 April 31 1901 Invalid date
Notice that all forms of equivalence class testing presume that the
variables in the input domain are independent; logical dependencies
are not recognized.
6/28/2021 25
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Strong Normal Equivalence Class Test Cases
• With 4 day classes, 3 month classes, and 4 year classes, the
Cartesian Product will have 48 equivalence class test cases.
(First Law of Software Engineering: The product of big
numbers is a bigger number)
• Note some judgment is required. Would it be better to have 5
day classes, 4 month classes and only 2 year classes? (40
test cases)
• Questions such as this can be resolved by considering Risk.
6/28/2021 26
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Revised NextDate Domain Equivalence Classes
• Month:
–M1 = { month : month has 30 days}
–M2 = { month : month has 31 days except December}
–M3 = { month : month is February}
–M4 = {month : month is December}
• Day
–D1 = {day : 1 <= day <= 27}
–D2 = {day : day = 28 }
–D3 = {day : day = 29 }
–D4 = {day : day = 30 }
–D5 = {day : day = 31 }
• Year (are these disjoint?)
–Y1 = {year : year is a leap year}
–Y2 = {year : year is a common year}
The Cartesian Product of these contains 40 elements.
6/28/2021 27
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
When to Use Equivalence Class Testing
• Variables represent logical (rather than physical)
quantities.
• Variables “support” useful equivalence classes.
• Try to define equivalence classes for The Triangle
Problem
• 0 < sideA < 200
• 0 < sideB < 200
• 0 < sideC < 200
6/28/2021 28
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Another Equivalence Class Strategy
• “Work backwards” from output classes.
• For the Triangle Problem, could have
– {x, y, z such that they form an Equilateral triangle}
– {x, y, z such that they form an Isosceles triangle with x = y}
– {x, y, z such that they form an Isosceles triangle with x = z}
– {x, y, z such that they form an Isosceles triangle with y = z}
– {x, y, z such that they form a Scalene triangle}
• How many equivalence classes will be needed for
x,y,z such that they are not a triangle?
6/28/2021 29
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
Assumption Matrix
Valid Values Valid and
Invalid Values
Boundary Value Robust Boundary
Value
Single fault
Weak Normal Weak Robust
Equiv. Class Equiv. Class
Worst Case Robust Worst
Boundary Value Case Boundary
Multiple fault Value
Strong Normal Strong Robust
Equiv. Class Equiv. Class
6/28/2021 30
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing
6/28/2021 31
Software Testing: A Craftsman’s Approach, 5th Edition Chapter 6 Equivalence Class Testing