Gieno    Equivalence Class Partitioning , Part I

Equivalence class partitioning (EQ) is a popular functional testing technique that provides a sense of complete coverage and helps avoid redundant testing. Equivalence class partitioning helps determine a minimum number of tests to achieve reasonable coverage. The tests are designed to evaluate input or output conditions for both the valid class and the invalid class partitions. The valid and invalid equivalence classes are generally derived from a set of values in which the union of the subsets is the entire set. The heuristics for identifying equivalence classes are:
 
      Range of values –a contiguous range of values. However, unions between subsets of non-contiguous ranges can also form a valid equivalence class. For example, a number field in which you can enter a value from 1 through 999. The valid equivalence class is >=1 and <=999. The two invalid equivalence classes are >1 and >999.
      Unique values in a group – any elements in a set of values that are handled differently than other elements in that same class. Unique elements must be separated into separate equivalence classes. For example, certain DBCS code point values in the Japanese character set on an ANSI based operating system may be problematic in some string parsing algorithms.
      Number of values – when a number of values or choices are permitted as long as all values are handled identically. For example, a list of items in a drop down list box which allows the user to select between 1 and 6 items from the list. The valid equivalence class is >=1 and <=6. The two invalid equivalence classes are no items selected, and selecting >6 items.
      Specific values –when a specific type of input condition “must be” or “must not be” present. For example, in SMTP the “@” symbol is a specific character that cannot be used as part of the email name or domain name.
 
For example, in the classic triangle problem a test case for the equilateral triangle would contain the test values of A = 4, B = 4, and C = 4.  This test case is a subset of the entire set of integers excluding special cases and boundary values. So, another test case using test values of A = 99, B = 99, and C = 99 would not likely to produce a different expected result so the test may be redundant and testing resources may be better spent testing other equivalence classes. But, specific values which may warrant additional tests may include -32,768 and +32,767 and 65,535 since these are the max int ranges for signed and unsigned 16-bit integers even though the max int value is a 32 bit integer.
 
Myers [1] outlines a process to derive a minimum set of equivalence class test cases from the valid and invalid equivalence classes. Although there is no mathematical formula for determining the number of test cases using Myers’ approach, it is a great approach to effectively reduce a potentially large number of tests to a more manageable set while maintaining reasonable probability of providing similar coverage. Myers’ approach states:
 
  • Write one test case which covers a many valid equivalence classes as possible until all valid equivalence classes are covered
  • Write one test case for every single invalid equivalence class until all invalid equivalence classes are covered
For example, a function takes two argument values. The form of the function is:
MyFunc (argv1, argv2)
where:
argv1 =
String of valid ASCII alpha-numeric characters (0x30 – 0x39, 0x41 – 0x5A, 0x61 – 0x7A)
String
length 4<>11

argv2 =
Unsigned 16-bit int value
Optional
Using this example, the first step to determine the minimum set of tests is to enumerate the valid and invalid equivalence classes for each argument’s input conditions. This is accomplished by creating a simple table or using a spreadsheet with three columns called an EQ Worksheet. In the first column list the input or output condition, in the second column list each valid equivalence class for each input condition, and in the third column list each invalid equivalence class for each input condition as in the example below.

Input/Output condition
Valid Equivalence Classes
Invalid Equivalence Classes
Argv1
EQA1 = Numbers (0x30-0x39)
I_EQA5 = ASCII char ≠ (0x30-0x39, 0x41 – 0x5A, 0x61 – 0x7A)
 
EQA2 = Upper Case letters (0x41 – 0x5A)
I_EQA6 = String length < 5
 
EQA3 = Lower Case letters (0x61 – 0x7A)
I_EQA7 = String length > 10
 
EQA4 = Total string length 4<>11 characters
 
Argv2
EQB1 = 0 – 65,535
I_EQB3 = > 65,535
 
EQB2 = empty
I_EQB4 = < 0
 
 
I_EQB5 = Not a Number
In this example we can see the valid equivalence class for Argv1 can be represented as:
Valid EQ Argv1 = EQA1 È EQA2 È EQA3 È EQA4
And the valid equivalence class for Argv2 can be represented as:
Valid EQ Argv2 = EQB1 Ç EQB2
Although both EQ B1 and EQ B2 are valid equivalence classes for Argv2 they must be tested independently because it is impossible to have both a valid int value and an empty value.
Thus, based on Myers’ process for defining valid equivalence class tests this function would require 2 tests for valid equivalence classes and 6 tests for invalid equivalence classes as outlined in the table below:

Test Case
Argv1
Argv2
1
EQA1 È EQA2 È EQA3 È EQA4
For example a string – Kv2nW9
EQB1
(For example 5,932)
2
EQA1 È EQA2 È EQA3 È EQA4
EQB2  (no value)
3
I_EQA5
EQB1
4
I_EQA6
EQB2
5
I_EQA7
EQB1
6
EQA1 È EQA2 È EQA3 È EQA4
I_EQB3
7
EQA1 È EQA2 È EQA3 È EQA4
I_EQB4
8
EQA1 È EQA2 È EQA3 È EQA4
I_EQB5
 
 
 posted on 2009-07-27 12:50  Gieno  阅读(556)  评论(0编辑  收藏  举报