Equivalence partitioning is a basic black box test case design technique.
In the previous blog post, we discussed about various test design techniques. Today let’s concentrate on equivalence partitioning.
Basics of Equivalence partitioning:
It divides the input domain of a program into classes.The input domain can be anything which may influence the outcome of the test (e.g. input fields, test cases, test environments, versions of product).
Each class is called as equivalence partition because all the elements in an equivalence class test the same thing. If one element in an equivalence class catches a bug, others also probably do the same. Also, if one element doesn’t catch a bug, others won’t either.
All the members of each equivalence class share some characteristics in common.These characteristics cannot be shared with the members of other classes.
The main idea of this test technique is to identify test cases by using one element from each equivalent class.
Why Equivalence partitioning ?
As we are considering the whole input domain in test design, it provides a completeness in testing. Also due to the disjoint nature of elements across different equivalence classes (not sharing traits with others) eliminate the possibility of redundancy in testing.
Finding Equivalence classes
Two people analyzing a program will come up with a different list of equivalence classes. This is a subjective process. The key of equivalence class testing is the choice of the equivalence relation that determines the classes. Mostly we make this choice by guessing the likely implementation that may be present in the program under test.
Now let me explain some test scenarios where we can apply equivalence partitioning technique.
Before going into the details, we need to understand two important terms. They are Valid equivalence classes & Invalid equivalence classes.
Valid Equivalence Classes:
It represents the valid input values to program under test for which the system behaves correct/normal.
Invalid Equivalence Classes:
This class represents the erroneous input values (i.e. invalid/unexpected conditions).For these conditions, either the system should reject them or it should escalate to user / do exception handling.
Test-case design by equivalence partitioning proceeds in two steps:
(1) identifying the equivalence classes and
(2) defining the test cases.
Example 1: “the month should be represented as a value from 1 to 12”
In the above example, the input condition month specifies a range of values i.e. 1 to 12.
So we can identify the following classes:
- One valid equivalence class (1 <= month <= 12)
- Two invalid classes (month < 1 & month > 12)
Example 2: “The input field value (eg. shapes) should be one among these : circle, rectangle or triangle .Each of these inputs handled in different ways in the program”.
As the condition states that each of these inputs handled by the program in unique way, the classes will be like below:
- Three valid equivalence classes for each input values (circle, rectangle and triangle)
- One invalid class (shape not specified in the condition e.g. diamond)
Example 3: ” the first character of username must be a number”.
- One valid equivalence class (username starts with number)
- One invalid equivalence class (username doesn’t start with number)
Hope these examples provides you a fair idea of how to apply equivalence partitioning in test cases.
We must have 1 )single dedicated test cases for each of these valid classes and
2) multiple test cases which are covering more than one valid classes in one test case
However we can’t combine multiple invalid classes in individual test cases. The reason is one invalid condition may mask/supersede the other. For instance, if the specification states that ” enter the course name (PHYSICS, CHEMISTRY, or MATHEMATICS) and the hours (10 – 15).
Suppose we wrote a test case combining two invalid classes like this : BIOLOGY, 5 (invalid course name and hours )
The system may say “BIOLOGY IS UNKNOWN COURSE TYPE”. It probably wouldn’t have checked the second invalid condition i.e. the course hours.
Hope you guys got an idea that how the equivalence class partitioning maximize the chance of uncovering as many defects as possible with reasonable amount of testing.
Feel free to add your comments below.