Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 60 ยท Test Design Techniques

Equivalence Partitioning

Learn equivalence partitioning: split inputs into valid and invalid partitions, pick one representative value each, and combine several inputs without exploding your test count.

You cannot test every possible input. A field that accepts an age between 0 and 120 already has 121 valid numbers, and a text box accepts countless strings. The question is how to choose a small set of tests that still gives you good confidence. Equivalence partitioning is the most basic answer.

The idea is to divide the possible inputs into groups, called partitions, where the software should treat every value in a group the same way. If the software handles one value in a group correctly, you assume it handles the rest correctly too. So you test one representative value from each partition instead of all of them.

Real versus stand-in. Equivalence partitioning is a thinking technique you apply to real requirements. The TryIt blocks use a small hand-written ticketPrice function and a short generator as stand-ins for a real system under test, so you can see the technique produce actual test cases.

Why it works

Take a cinema that sells tickets by age: children up to 12, adults 13 to 64, seniors 65 and older. The program has three branches. Testing ages 7, 8 and 9 exercises the same branch three times and teaches you nothing new. Testing 7, 30 and 70 touches all three branches with three tests.

That assumption has a limit: it is only as good as your partitions. If the code secretly treats 10 differently from 11, your partitions were wrong, and no technique can find a defect in a case you did not test. Partitioning reduces the number of tests; it does not remove the need to think. The Seven Testing Principles explains why exhaustive testing is impossible and why selecting tests by risk and structure is the practical alternative.

Valid and invalid partitions

Every input has valid partitions, where values are accepted and processed, and invalid partitions, where values should be rejected or handled as errors. Testers who skip invalid partitions miss many defects, because error handling is where software is often weakest.

For the cinema's age field, the requirement says: "Age is a whole number from 0 to 120."

Partition Values Valid? Expected
Below range -1 and lower invalid error
Child 0 to 12 valid price 5
Adult 13 to 64 valid price 12
Senior 65 to 120 valid price 8
Above range 121 and higher invalid error
Not a whole number 3.5 invalid error
Not a number "abc" invalid error
Empty nothing entered invalid error

Partitions come from the requirement and from the data type. The first five come from number ranges. The last three come from asking what else a user could type.

Equivalence partitioning in four steps

List inputs Find every input the feature accepts.
Split into partitions Group values the system should treat alike.
Pick one each One representative per partition.
Add expected result Decide pass or fail before running.

Do the same for valid and invalid partitions.

1 / 2

Choosing representatives

Any value in a partition is a valid representative. People often pick a value from the middle, such as 6 for children and 40 for adults, because it is clearly inside the partition and far from the edges. The edges themselves are covered by the next technique, Boundary Value Analysis, which complements partitioning. Used together they find far more defects than either alone.

If the partitions do not overlap and cover all values, partition coverage is the percentage of partitions that have at least one test. With eight partitions and eight tests, coverage is 100 percent.

The first stand-in has a ticketPrice function and one test for each partition in the table. Each test states an expected result before running.

JS One test per partition

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Eight tests cover the whole behavior of the field. Compare that with the 121 valid ages you would need for naive exhaustive testing, and you can see the saving.

Multiple inputs

Real features have several inputs. If each has its own partitions, testing every combination multiplies the numbers quickly. Consider a discount rule with three inputs:

  • Customer type: regular, member, staff (3 partitions).
  • Order total: below 50, from 50 to 199.99, 200 or more (3 partitions).
  • Payment: valid card, expired card (2 partitions).

Every combination gives 3 x 3 x 2 = 18 tests. For large forms that becomes hundreds. Two common strategies reduce it:

  • Each-choice coverage. Make sure every partition of every input appears in at least one test. The minimum number of tests equals the largest number of partitions in any one input (here 3). It is cheap but does not test combinations.
  • Valid-first with single invalid values. Build valid tests that combine one valid representative from each input. For invalid inputs, test one invalid value at a time while keeping the other inputs valid. If you put two invalid values in one test, you cannot tell which one the software rejected, and one error can hide the other.

When combinations matter, use a smarter method: Decision Table Testing for rules that depend on conditions, or Pairwise and Combinatorial Testing to cover every pair of values compactly.

The second stand-in counts the combinations and then generates each-choice tests, plus one test per invalid partition.

JS Each-choice tests for several inputs

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice how the generated invalid tests keep every other input valid, and how the three valid tests wrap around the shorter lists with the modulo operator. That cycling is a simple way to make each-choice rows, though a real tester also checks that sensible combinations are included.

Partitions beyond numbers

Equivalence partitioning is not only for numbers. You can partition:

  • Text: empty, one character, normal, maximum length, longer than the maximum, only spaces, special characters, non-Latin characters.
  • Sets of values: each allowed value is its own partition, plus one value outside the set. For a "country" dropdown that is every country you consider distinct, plus a missing value.
  • Dates: past, today, future, invalid date such as 30 February.
  • Time and state: before opening, during opening hours, after closing.
  • Output partitions: group the expected outputs instead of the inputs, then choose inputs that produce one of each output.

Common mistakes

  • Forgetting invalid partitions, then wondering why error handling is untested.
  • Overlapping partitions, which confuses expected results.
  • Mixing two invalid inputs in one test.
  • Picking the edge value as the representative and thinking it is enough. The edges deserve their own tests.
  • Treating the technique as proof. Passing one test in a partition does not prove every other value passes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main idea of equivalence partitioning?

    Partitioning assumes every value in a partition is handled the same way, so one representative is enough.
  2. 2. An age field accepts whole numbers from 18 to 60. How many partitions are there if you only consider the number range?

    Below 18 (invalid), 18 to 60 (valid) and above 60 (invalid) give three partitions.
  3. 3. Why test one invalid value at a time?

    With two invalid inputs in one test, a single error message could hide the second problem, and you cannot tell what the system checked.
  4. 4. Three inputs have 3, 4 and 2 valid partitions. What is the minimum number of tests for each-choice coverage?

    Each-choice needs as many tests as the input with the most partitions, which is 4. All combinations would be 24.

Summary

  • Equivalence partitioning splits inputs into partitions that the software should treat alike, then tests one representative from each.
  • Always include invalid partitions: out of range, wrong type, empty and unusual formats.
  • Partitions should not overlap and should leave no gaps.
  • For several inputs, use each-choice coverage and test one invalid value at a time.
  • Combine partitioning with boundary value analysis, since defects cluster at the edges of partitions.

Next: Boundary Value Analysis.