QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals › Test design techniques

What are equivalence classes?

An equivalence class is a group of values the system handles by one rule, so one representative per class is enough. For an amount from 1 to 10,000 these are a value in range, below 1, above 10,000 and non-numeric input: text, an empty field. Invalid classes are tested one per test, because the first validation error masks the rest, and boundary values are added near the edges.

QA Fundamentals · Test design techniques

The amount field accepts 1–10,000. How many values do you enter instead of trying all ten thousand?

The transfer form has an "Amount" field, and the requirements say: from 1 to 10,000 UAH. You cannot try every value, and testing only "500" and "1000" is unreliable: all those checks pass the same branch of code. The equivalence partitioning technique answers which values are enough and why exactly those.

How it works and why

The idea is simple: values that the system handles by one rule belong to one class. If the code implements "an amount from 1 to 10,000 is accepted, the rest is rejected", then 500 and 7,777 go through the same branch. A test with the second value gives no new information, so one representative per class is enough. In ISTQB CTFL v4.0 (4.2.1), 100% coverage means every class, invalid ones included, is covered by at least one test. A separate practical rule: one test does not combine several invalid values.

The last rule explains why invalid classes are checked one at a time. If one test enters both an amount of 0 and an empty date and the system shows a single error, you will not know whether it handles the second one. The first validation "masks" the rest.

Three numeric classes and one representative each

invalidvalidinvalid < 1 1 … 10,000 > 10,000 05,00020,000 Separate classes: “abc”, empty, spaces
Figure 1. The amount field splits into three numeric classes; non-numeric input forms its own invalid classes.

Example: from classes to tests

First list all the classes, not only the numeric ones. Then give each a representative and an expected result, taken from the requirements and not from what the system did.

ClassRepresentativeExpected
Valid: 1–10,0005,000Transfer accepted
Below 10Minimum error
Above 10,00020,000Maximum error
Negative (if a separate rule checks the minus sign)-100Format error: negative amount
Too many decimals100.555Rejected or rounded, as the requirements say
Not a numberabcFormat error
Empty field(nothing)Field is required

Seven tests cover seven classes. A negative value formally lies in the class "below 1"; it is a class of its own only when the system handles it by a different rule, because classes must not overlap. The weak set "100, 500, 1000, 5000" also has four values, but all of them lie in one class, so six of the seven classes stay unchecked.

A set of values: weak and strong

Typical

Four values in one class

100, 500, 1000, 5000: all valid. Plenty of tests, and not one rejection branch is checked.

Better

One value from each class

5,000, 0, 20,000, -100, 100.555, abc, empty. Each test checks a separate handling branch.

Figure 2. How many tests matters less than how many different classes they cover.

For a form with several fields, the valid representatives of different fields are merged into one "happy" test, and an invalid value is always entered in only one field at a time.

Limits and alternatives

  • Classes come from the requirements and from what is known about the implementation. If the code has a hidden branch (for example, amounts above 5,000 need an SMS confirmation), that is a separate class, and it is visible only from clarifications to the requirements.
  • One representative per class is not enough when the class edges are unclear or the code is wrong near the edges. That is why the technique is almost always combined with boundary value analysis.
  • When the result depends on a combination of fields, the classes of single fields do not settle it. A decision table or pairwise helps here.

Typical mistakes

  • Taking values from one class. Many tests do not mean wide coverage.
  • Combining several invalid values in one test. The first validation error hides the rest.
  • Forgetting non-numeric classes. Empty, spaces, text and a very long number often break first.
  • Inventing the expected result after the run. Then the test confirms behaviour instead of a requirement.

Check yourself

The "quantity" field accepts 1 to 99. How many numeric classes are there and what are the representatives?

Answer

Three numeric classes: below 1 (for example 0), from 1 to 99 (for example 50) and above 99 (for example 150). Other invalid classes are added to them: text, an empty field, a fractional value. The total is not three tests but as many as there are different handling rules.

Why enter an invalid value in only one field per test?

Answer

If one test has two invalid fields, the system often shows only the first error. You will not learn whether the second field is checked, and you will not understand which error fired. A separate test gives an unambiguous conclusion.

All your values 100, 500, 1000, 5000 passed. Can you say the field is tested?

Answer

No. They all come from one valid class, so the rejection branches (below 1, above 10,000, text, empty) were never executed. One class out of several is covered.

In an interview. Junior: I split the input into groups where the system behaves the same and take one representative from each, valid and invalid. For an amount from one to ten thousand that means a value inside the range, below, above, text and an empty field. This shortens the number of tests without losing coverage. Middle/Senior: I derive the classes from the requirements and the known implementation, look for hidden branches (limits, confirmations) and ask the analyst about them. I check invalid classes one per test so one error does not mask another, and I add boundary values near the edges, because a single representative does not catch a "greater than or equal" mistake.

More articles in this chapter