Thursday, March 4, 2010

Equivalence Partitioning Demystified

This is another terminology that we normally come across while discussing about Software Testing. Equivalence Partitioning is one of the methods that we use in order to reduce the test cases, without having impact on the test coverage. While testing, we should always make sure that none of the scenarios are left out from testing. At one point or the other, the condition should be met. Equivalence Partitioning is been defined in such a manner that the test effectiveness does not get impacted, but the number of cases certainly reduce. If we look for a definition, then a probable and good one to adopt could be "In order to reduce the number of test cases which check the software’s behavior to various input data values, we categorize the input data into different partitions. These partitions, called as equivalence partitions, are those set of input data which make the software to provide a similar type of output or behave similarly."

The definition might be sounding complex. Let me try to explain it in simpler terms. When you think about testing a module of software, one thing that might catch attention is testing against different input data. There could be many different scenarios of testing software, with each of these scenarios requiring multiple sets of data. This is where equivalence partitioning helps! You divide the input data into different sets, based on the output that the software provides, or the way that the software behaves with inputs. These sets of data for which the software behaves in a similar fashion, or provides similar type of outputs, are called as equivalence partitions. This ensures test effectiveness, considering the fact that there are no cases which are neglected, as well as reduces the number of test cases which need to be executed.

Let me get more into the details with the help of an example. Consider the VBScript code that is given below. This is a simple calculator code which can perform addition, subtraction, multiplication and also division.


Dim Val01, Val02, OpValList, Operator, OutVal


Val01 = InputBox("Please enter the first number")
If IsNumeric(Val01) Then
  Val01 = FormatNumber(Val01)
  OpValList = "Select one of the Operators" & Vbcrlf & Vbcrlf & "1 - Addition" & Vbcrlf & "2 - Subtraction" & Vbcrlf & "3 - Multiplication" & Vbcrlf & "4 - Division"
  Operator = InputBox(OpValList, "Select Operator", 1)
  If IsNumeric(Operator) Then
    Val02 = InputBox("Enter the Second Number")
    If IsNumeric(Val02) Then
      Val02 = FormatNumber(Val02)
      Select Case Operator
      Case 1
        MidVal = Val01 + 0
        OutVal = MidVal + Val02
        MsgBox Val01 & " + " & Val02 & " = " & OutVal
      Case 2
        OutVal = Val01 - Val02
        MsgBox Val01 & " - " & Val02 & " = " & OutVal
      Case 3
        OutVal = Val01 * Val02
        MsgBox Val01 & " * " & Val02 & " = " & OutVal
      Case 4
        OutVal = Val01 / Val02
        MsgBox Val01 & " / " & Val02 & " = " & OutVal
      Case Else
        MsgBox "Invalid Operator Selection!"
      End Select
    Else
      MsgBox "Invalid Input, Only Numbers are expected"
    End If
  Else
    MsgBox "Invalid Input, Only Numbers from the list are expected"
  End If
Else
  MsgBox "Invalid Input, Only Numbers are expected"
End If


Lets consider testing the above mentioned code snippet. What could be possible set of inputs that we can think of? Of the four functionalities, the Equivalence Partitions/input data sets could be of either
In each of the above categories, there are infinite amount of numbers belonging to each set. In order to perform an equivalence portioning, we choose any random value which belong to each set, and test it with the software. Suppose we chose values like
What have we achieved? We have covered all the scenarios that have been identified, and that too effectively testing each of the conditional statements in the code. How many inputs have we checked the code with? Just 4 test cases. Now, you might have gained a fair idea about the significance of using this technique in software testing process.

Labels: ,


Comments:

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]