QA AND TEST AUTOMATION · PART 1 · MANUAL TESTING, PROPERLY · TECHNIQUE · 9 OF 112

Equivalence Partitioning in Testing, With Examples

How to test a field with a handful of cases instead of thousands: split inputs into valid and invalid partitions that the software treats the same way, pick one value from each, and know when one value is not enough. Worked on ShopRung quantity, search and password rules, with partitions for outputs and for more than one field.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 14

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Group inputs treated alike
  • valid and invalid
  • one value per group
  • type and output partitions
  • add boundaries

Notes

The problem

Take the quantity box on a ShopRung product page. It could receive any whole number, negative numbers, zero, decimals like two point five, text, an empty value or a giant number. Trying them all is impossible, which is one of the seven testing principles. Trying random ones is a waste. We need a reason to pick each value. That reason is how the software is supposed to treat it.

One quantity box
  • whole numbers: ..., -1, 0, 1, 2, ..., 10, 11, ..., 9999
  • decimals: 2.5, 0.1
  • text: "two", "", " "
  • huge: 99999999999
  • principle 2: exhaustive
  • testing is impossible
  • so which ones do we try?

The idea

An equivalence partition is a group of inputs that the requirement says must be handled the same way. If a quantity of four is accepted, there is no reason in the rules for five or seven to behave differently. So one test stands for the whole group. You trade thousands of tests for a few, on purpose, and you can explain why each one is there. You will also hear the name equivalence class. It means the same thing.

Equivalence partition
  • a group of inputs (or outputs)
  • that the requirement says
  • must be handled the same way
  • assumption: if 4 works, 5 and 7 work too
  • one test per partition
  • instead of one per value
  • also called equivalence class

Find partitions

Read the rule. Cart two says each cart line has a quantity from one to ten. That draws two lines on the number line, and makes three partitions. Below one is invalid. One to ten is valid. Eleven and above is invalid. Pick one value from each, say zero, five and fifteen. The two invalid ones must be refused with the message: quantity must be between one and ten. Three tests, each with a reason.

CART-2: quantity 1 to 10
   ... -1  0 | 1 ... 10 | 11 ...
   invalid   |  valid   | invalid
   too low   |          | too high

pick one from each:
   0  → refused
   5  → accepted
  15  → refused

both invalid: "Quantity must be
  between 1 and 10"

Invalid types

Invalid partitions also come from the type of the input, not only its size. A decimal like two point five, text like the word two, an empty value and a negative number are all different kinds of wrong, and the code may handle each in a different place. In ShopRung, sending a quantity of two point five to the API returns status four hundred with invalid quantity. Give each invalid partition its own test, so one error message cannot hide another.

More invalid partitions
  • not a whole number 2.5
  • not a number "two"
  • empty ""
  • negative -3
  • ShopRung API: quantity 2.5 → 400 invalid_quantity
  • each invalid partition gets
  • its own test, one at a time

Search example

Now the ShopRung search. Rule search three says the text must be two to fifty characters after trimming the spaces. That gives three length partitions: zero or one character is refused, two to fifty is searched, fifty one and more is refused with its own message. Trimming adds a sneaky one: three spaces look like three characters but trim to none. And search two adds a partition for case: mug in capitals must find the same two mugs.

Search text partitions
  • length 0 to 1 invalid "m" → "Search needs at least 2 characters"
  • length 2 to 50 valid "mug" → 2 products
  • length 51 and up invalid "Search can be at most 50 characters"
  • spaces only " " trims to 0
  • case: "MUG" = "mug" (SRCH-2)

Several rules

A password in ShopRung has three rules: eight to sixty four characters, at least one letter, and at least one digit. Partition each rule. The valid case meets all of them, like abcdefg1. Then write one invalid case per rule, and break only that rule in each case: a short password, one with no digit, one with no letter, and one that is sixty five characters. If a case broke two rules at once, you would not know which check refused it.

ACC-5: the password
  • length < 8 | 8..64 | > 64
  • letter has one | has none
  • digit has one | has none
  • valid: "abcdefg1"
  • invalid: "abc1" (too short) "abcdefgh" (no digit) "12345678" (no letter) 65 characters
  • one rule broken per case

How many cases

How many cases do you need? Valid partitions can share a case, when they do not interfere, because a passing case tells you all of them worked. Invalid partitions need one case each, with everything else valid, because the first error usually stops the processing and hides the rest. So for the password, that is one valid case plus four invalid ones: five cases instead of millions of possible strings.

Counting the cases
  • valid partitions: cover several in one case when they are independent
  • invalid partitions: one per case, everything else valid
  • minimum = max(valid groups) + number of invalid groups (for one field: 1 + invalids)

Output partitions

Partitions are not only about inputs. Look at what comes out. Shipping in ShopRung has three possible outputs: four ninety nine below seventy five dollars, free at seventy five and above, and zero for an empty cart. Make sure each output appears in at least one test. The same goes for messages. Every distinct error message the requirements promise is an output partition, and each one deserves a test that makes it appear.

Shipping outputs (PRICE-9)
  • after-discount subtotal $0.01 .. $74.99 → $4.99 $75.00 and up → free empty cart $0.00 → $0.00
  • check each output appears
  • at least once: $4.99, Free, $0.00
  • messages are outputs too

The catch

Here is the catch. Equivalence partitioning assumes the code treats every value in a group the same. Bugs love the edges between groups. Imagine a developer wrote quantity greater than one instead of greater than or equal to one. Your three cases, zero, five and fifteen, all pass. But a quantity of exactly one is wrongly refused, and nobody tested it. That is why partitioning is always paired with the next technique, boundary value analysis.

Where EP alone misses
  • code written: if (q > 1 && q <= 10) // bug
  • EP picks 0, 5, 15: 0 refused ok 5 accepted ok 15 refused ok
  • but 1 is wrongly refused → also test the boundaries

Rules of thumb

Some quick habits. A range gives one valid and two invalid partitions. A set of named values, like the order statuses, gives one partition per value. A must have rule gives has and has not. A format gives valid, wrong type, empty and too long. For partitioning alone, pick a value from the middle of each group. Write the partitions in a small table before writing cases. It makes the reasoning visible, and reviewers can spot a missing group.

Rules of thumb
  • a range → 1 valid, 2 invalid
  • a set of values → 1 per value (each order status)
  • a must-have → has / has not a format → valid, wrong type, empty, too long
  • pick a middle value for EP, edges for BVA
  • write the partitions in a table before the cases

Common mistakes

Common mistakes. Testing only the valid partition. Putting two invalid values in one case. Forgetting empty input and input that is only spaces. Forgetting type partitions like text and decimals. Deriving partitions from what the screen happens to allow, instead of from the requirement. Remember that the ShopRung quantity box allows you to type eleven on purpose, so the server rule is what you test. Ignoring outputs. And stopping before boundary values.

Avoid these
  • only valid partitions
  • two invalid values in one test case
  • forgetting empty and spaces
  • forgetting type partitions (text, decimals)
  • partitions from the UI, not the requirement
  • skipping output partitions
  • stopping at EP, no BVA

Say it like this

Interviewers ask for a definition and an example, often an age field from eighteen to sixty. Say: I split the inputs into groups the system should treat the same way, valid and invalid, and test one value from each. For age eighteen to sixty, the groups are below eighteen, eighteen to sixty, above sixty, plus non numbers and empty. Then add: I always combine it with boundary value analysis, because bugs sit at the edges.

In the interview
  • "I split the inputs into groups the system should
  • treat the same way, valid and invalid, and test one value
  • from each. For an age field
  • of 18 to 60: below 18, 18 to 60, above 60, plus non-numbers
  • and empty. I always add
  • boundary values, because bugs
  • sit at the edges."

Interview questions

Q1What is equivalence partitioning?

A test design technique that divides inputs (or outputs) into groups the system should treat the same way, valid and invalid, and tests one representative value from each group instead of every value.

Q2Give the partitions for an age field that accepts 18 to 60.

Valid: 18 to 60. Invalid: below 18, above 60, non-numeric, decimal, and empty. One test per invalid partition, and one valid value such as 35, plus boundary values 17, 18, 60, 61.

Q3Why test invalid partitions one at a time?

Because the first validation error usually stops processing and hides the others. With one invalid value per case, a failure points to exactly one rule.

Q4How many test cases does equivalence partitioning need at minimum?

Enough to cover each valid partition at least once (valid ones can share a case) plus one case for each invalid partition.

Q5What is the weakness of equivalence partitioning?

It assumes every value in a partition behaves the same. Off-by-one bugs at the edges between partitions slip through, so it is paired with boundary value analysis.

Q6What are output partitions?

Groups of distinct results the system can produce, such as free versus paid shipping or each error message. Each output should appear in at least one test.

Q7Is equivalence partitioning black-box or white-box?

Black-box: partitions come from the requirements and the expected behaviour, not from the code.

Q8How would you partition a search box?

By length (too short, valid, too long), by content (matches, no match, special characters), by case, and by spaces (leading, trailing, only spaces), using the rules the requirement states.