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

API › Test design for APIs

Equivalence classes and boundary values for fields and parameters

An equivalence class is a set of values the server reacts to in the same way, so one representative per class is enough. Boundary values are taken on both sides of each limit (for 1 to 100: 0, 1, 100 and 101), because comparison bugs such as >= instead of > show up only near the threshold. Limits come from the specification, not the form.

API · Test design

A field accepts 1…100. Which values do you test so you do not write a hundred tests?

The spec says: quantity in an order is an integer from 1 to 100. A beginner writes tests for 5, 50 and 500, everything is green, and in production a customer cannot order exactly 100 items. The cause is one character: the server compares with >= 100 instead of > 100. You cannot try every value, so you need a way to pick a few values so that such mistakes do not slip through.

POST /v1/orders
{ "sku": "A1", "quantity": 25 }

quantity: integer, minimum 1, maximum 100

Below: how to split values into classes, why bugs live on the boundaries, and how to turn it into a short Playwright test.

How it works and why

An equivalence class is a set of values the server reacts to in the same way. For quantity there are four: valid 1…100, below the minimum, above the maximum, not an integer. The assumption is simple: if 25 passes, then 26 and 60 pass through the same branch of code, so one representative per class is enough.

Boundary values are needed because code compares a number with a threshold, and comparison mistakes (< instead of <=, off-by-one) show up only near the threshold. So at each boundary you take a value from both sides: two-value analysis is 0 and 1, 100 and 101. Three-value analysis adds the neighbour from the inside: 0, 1, 2 and 99, 100, 101. It fits when the logic is more than a single comparison.

Boundaries of the quantity field

422201422 < 1 1 … 100 > 100 0 | 1100 | 101
Figure 1. Three classes and two boundaries. Values on a boundary are taken as a pair: one on each side of the threshold.

Where the boundaries come from. From the specification (in OpenAPI that is minimum, maximum, maxLength, enum), or, when there is none, from the requirements and questions to the developer. If the server accepts more than is written (say, 101), that is also a finding: either the spec is outdated or the validation is missing.

Example: from "three random values" to a table with boundaries

Before: tests for 5, 50 and 500. The wrong check >= 100 lets them all through:

// the server (a mistake): 100 is rejected, 101 slips through
if (quantity < 1 || quantity >= 100) reject();   // should be > 100

5 and 50 are accepted, 500 is rejected, the test is green. After: a table of classes and boundaries where each row asks its own question.

const cases = [
  { quantity: 0, status: 422 },      // just below the minimum
  { quantity: 1, status: 201 },      // minimum
  { quantity: 2, status: 201 },
  { quantity: 99, status: 201 },
  { quantity: 100, status: 201 },    // maximum
  { quantity: 101, status: 422 },    // just above the maximum
  { quantity: 1.5, status: 422 },    // not an integer
  { quantity: '25', status: 422 },   // wrong type
  { quantity: null, status: 422 },
];

for (const c of cases) {
  test('quantity ' + JSON.stringify(c.quantity), async ({ request }) => {
    const res = await request.post('/v1/orders', {
      data: { sku: 'A1', quantity: c.quantity },
    });
    expect(res.status()).toBe(c.status);
  });
}

The row quantity: 100 fails at once on the wrong comparison, and the test names the value in its title. The rows 1.5, '25' and null are separate classes: the server may handle them in different branches (type coercion, a null check) rather than in one range validation. Status 422 here follows the examples of this course; your API may use 400, what matters is that it matches the spec.

The same approach works for strings: length 0, 1, the maximum, the maximum plus one; spaces, unicode, an emoji.

const names = [
  { name: '', ok: false },                 // 0 characters
  { name: 'A', ok: true },                 // 1
  { name: 'A'.repeat(50), ok: true },      // 50
  { name: 'A'.repeat(51), ok: false },     // 51
  { name: '   ', ok: false },              // spaces only
  { name: 'Олена 😀', ok: true },          // unicode and an emoji
];

Limits and alternatives

  • One invalid field per request. If you break two fields at once, the server reports one of them and you learn nothing about the other. Keep the remaining fields valid.
  • Other kinds of parameters. Query limit 1…100: 0, 1, 100, 101, -1, abc, an empty limit=. An enum (status=paid|shipped): every allowed value, a value outside the list, another case (PAID). A "from, to" range: from greater than to, and equal values. A date: the start and end of the range, 29 February, the format (2026-11-09 versus 09.11.2026), the time zone.
  • String length can be counted in characters, bytes or code units. An emoji such as 😀 takes two UTF-16 code units (and composed emoji even more), so "50 characters" may mean different things in different layers (server, database). That is a separate case on the boundary.
  • Boundary analysis does not replace reading the code and the business rules. If a discount starts from 1000, then 1000 is a boundary that is not in the field schema. It is known from the requirements.
  • For many fields at once there are combinatorial methods (pairwise), covered in the lesson on parameter combinations.

Common mistakes

  • Checking only the middle of the range. Boundaries are what catch off-by-one, and they produce most validation defects.
  • Taking boundaries from the UI, not from the spec. The form on the front end limits to 100, while the API accepts 100000: clients that call the API directly bypass the form.
  • Generating a hundred tests, one per value. It is slow, adds nothing within a class and hides important cases in noise.
  • Forgetting the upper limit of the type. A field with no maximum still hits the database type: 2147483648 may end in a 500 instead of a 422.

Check yourself

The name field has a length of 1…50. Which five or six length values do you take first, and why?

Answer

0, 1, 50 and 51 characters: two boundaries, each from both sides. In addition a string of only spaces, unicode with an emoji, and a middle value. Boundaries catch comparison mistakes, while spaces and unicode are separate classes that the server may handle differently.

A test sends { "quantity": 0, "sku": "" } and gets 422. What is wrong with this test as a boundary check?

Answer

Two fields are invalid at once. The 422 may come only from the empty sku, and you do not know what happens with quantity: 0. For each case you break one field and keep the rest valid.

In an interview. Junior: I split values into equivalence classes, take one representative of each and check the boundaries separately: the minimum, the maximum and the values right beyond them. For each field I add a wrong type and an empty value. Middle/Senior: I take boundaries from the specification, not from the form. I break one field at a time so that the response points at one cause. For logic with a more complex comparison I add neighbours (three-value analysis), and typical traps such as length in bytes or the upper limit of a database type stay as separate cases.

More articles in this chapter