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
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 throughif (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.
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.
Related lessons: “Required, optional, null, empty and extra fields; types and formats”, “Request and response body: types, null and empty values”, “Positive and negative cases”.
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.
Required, optional, null, empty and extra fields; types and formats
A missing key, an explicit null and an empty value are three states of a field with separate validation branches, so each is its own case. A required field must give an error naming the field, an optional one must succeed. Types, formats, extra fields (a saved role is mass assignment) and a broken structure are checked too; the last must give a controlled 4xx, not a 500.
API · Test design
The email field: missing, null, empty. Is that one case or three?
A developer says: "Email is required, validation exists." You send {}, get 422 and close the case. Meanwhile {"email": null} goes through and the database gets a user with no email, because the check looked only at a missing key. Beyond values, a request body is checked for the presence and shape of each field, and that produces a table of negative inputs.
Below: how "missing", null and "empty" differ, and what to do about types, formats, extra fields and a broken structure.
How it works and why
JSON distinguishes three states of a field, and each goes through its own branch of server code. The deserializer sees a missing key (undefined, or "value not set"), an explicit null and an empty value ("", [], {}). Validation is written as separate conditions, and it is easy to skip one.
Three states of one field
Missing
{ }
"The client did not send the field". In PATCH it means "leave it alone".
null
{ "email": null }
"There is no value". In PATCH it usually means "clear it".
Empty
{ "email": "" }
There is a value, but with no content. A separate case, like a string of spaces.
Figure 1. Three different inputs. The server may handle them differently, so each goes into its own test.
For a required field we expect a validation error (400 or 422 by agreement) naming the field. For an optional field we expect success and a default value. It also matters whether the server confuses "not sent" with "sent null": in PATCH (JSON Merge Patch, RFC 7396) null means "remove the field" and a missing key means "do not change".
Example: from one negative case to a presence table
Before: one test with {}. It is green, while null and an empty string are unchecked. After: a table where each state is its own test and all of them require the field to be named in the error.
If the "null" row fails with status 201, that is a real defect: validation does not cover an explicit null. Checking errors[0].field guarantees the rejection is about the email and not something else.
Types and formats. For each field take a value of a foreign type. Silent coercion ("30" became 30) is also a defect when the spec says "integer": a client that sends a string breaks once the server changes.
{ "age": "30" } // string instead of an integer
{ "age": 30.0 } // is it an integer? depends on the schema
{ "tags": "a,b" } // string instead of an array
{ "address": [] } // array instead of an object
{ "id": 9007199254740993 } // above 2^53-1: a JS client rounds it
Formats (email, URL, UUID, phone, date and time per ISO 8601, currency and country codes) are checked with three samples: a valid one, one with an error inside, and an edge case (a@b, a trailing space, upper case).
Extra fields. A server may ignore or reject an unknown field, and both behaviours are acceptable if they match the spec. The other variant is dangerous: a field that must not be changeable (role, balance, id) is suddenly stored. That is mass assignment.
test('role in the body is not applied (mass assignment)', async ({ request }) => {
const res = await request.post('/v1/users', {
data: { name: 'Olena', email: 'qa+1@test.example', role: 'admin' },
});
expect([201, 422]).toContain(res.status()); // ignore or reject: per specif (res.status() === 201) {
const { id } = await res.json();
const user = await (await request.get('/v1/users/' + id)).json();
expect(user.role).toBe('user'); // must not become admin
}
});
Request structure. Broken JSON, an empty body, a wrong Content-Type, an excessively long body, a duplicate key. Each must produce a controlled 4xx, not a 500.
test('broken JSON gives a controlled 400', async ({ request }) => {
const res = await request.post('/v1/users', {
headers: { 'Content-Type': 'application/json' },
data: Buffer.from('{ "name": "Olena", '), // a Buffer is sent byte for byte
});
expect(res.status()).toBe(400);
expect(res.headers()['content-type']).toContain('json');
});
Limits and alternatives
"Ignore or reject an extra field" depends on the API. Strict APIs answer 400/422 to an unknown field, lenient ones silently ignore it. The test checks what the spec promises, not personal taste.
A duplicate key in JSON. RFC 8259 recommends unique names and does not define the behaviour for duplicates: many parsers take the last value, others report an error or all pairs. It is a useful security case (different layers see different values), but the expected response depends on the project.
Dates. ISO 8601 with a time zone (2026-11-09T10:00:00Z) and without one may be interpreted differently by the server. Check both.
A schema helps. With OpenAPI, most of the table can be generated from required, nullable, type, format, but manual cases such as "a string of spaces" still remain with you.
Common mistakes
Merging the three states into one case. A test with {} does not prove that null and "" are rejected too.
Checking only the status of a negative request. A rejection with no state change proves little: after a 422 check that nothing was created, and in an update that the value did not change.
Accepting type coercion as normal. "It works with a string too" means the contract is blurred, and clients start relying on it.
Not looking for mass assignment. Add role, isAdmin, balance, id, ownerId to create and update and see whether they were stored.
Check yourself
PATCH /users/7 receives { "middleName": null } and { }. How do the expectations differ?
Answer
With null the field is cleared (per JSON Merge Patch), with an empty body nothing changes. A test for it: send null and check that GET returns the field empty (null or absent, per the spec); send another field and check that middleName stayed the same.
The server answered 422 to { "role": "admin", "name": "Olena" } when creating a user. Is that a bug or fine?
Answer
Fine, if the spec says to reject unknown or forbidden fields. It would be a bug if the response were 201 and the role was stored. That is why the test checks not only the status but also that after a 201 role did not become admin.
Related lessons: “Equivalence classes and boundary values for fields and parameters”, “Request and response body: types, null and empty values”, “Positive and negative cases”, “Excessive data, mass assignment, injections, rate limiting”.
In an interview.Junior: For a field I tell apart missing, null and empty, and I check wrong types, formats and extra fields. A negative test checks both the status and that the state did not change. Middle/Senior: These three states go through different validation branches, so each is a separate case, and in PATCH they even mean different things. I check extra fields for mass assignment: whether role, balance, id get stored. A broken structure (JSON, Content-Type, a duplicate key) must give a controlled 4xx, not a 500, and I take the table from OpenAPI as a base but add manual cases.
Parameter combinations, resource states and CRUD flows
Parameter combinations are covered with pairwise testing: a minimal set where every pair of values of two parameters appears at least once. It relies on most defects coming from the interaction of one or two parameters, but full enumeration is still justified for money and permissions. A resource with states gets a transition table covering allowed and forbidden transitions (usually 409), and after a refusal the state is checked to be unchanged.
API · Test design
Three sort and filter parameters give 12 combinations. How many tests do you really need?
Each field has been checked on its own, and a bug still arrives from production: GET /products?sort=rating&order=desc&inStock=true returns a list that is not sorted. Each parameter works alone, their combination breaks. The second source of such defects is time: an order was cancelled after shipping, and the money came back. Below: parameter combinations, resource states and CRUD chains.
How it works and why
Parameter combinations. The endpoint GET /products with parameters sort (price, name, rating), order (asc, desc) and inStock (true, false) has 3 × 2 × 2 = 12 combinations. The count explodes as parameters grow, and pagination and filters add more. Pairwise testing takes a minimal set in which every pair of values of two parameters appears at least once. Here 6 tests are enough instead of 12:
#
sort
order
inStock
1
price
asc
true
2
price
desc
false
3
name
asc
false
4
name
desc
true
5
rating
asc
false
6
rating
desc
true
The approach rests on an empirical observation: most defects are caused by the interaction of one or two parameters, not three or more. So the saving grows with the number of parameters (for 10 parameters with 3 values each, the full product is 59,049 combinations, while a pairwise set takes about 15–20 rows). Such a set is generated by tools (PICT, AllPairs), and dangerous combinations such as dependent parameters (from greater than to) are added by hand.
Resource states. Many resources have a life cycle: an order created → paid → shipped → delivered plus separate cancelled, refunded. It is a finite state machine: only certain transitions are allowed, and the rest must be rejected.
Order states and a forbidden transition
Figure 1. Allowed transitions go down, a forbidden one (cancelling a shipped order) must give 409 and leave the state unchanged.
Build a table of transitions and check both sides: every allowed transition works and the new state is visible through GET, every forbidden one gives an error (usually 409 Conflict) and the state does not change. A separate case is repeating the same transition, because paying twice must not charge twice.
Example: a transition table in a test
Before: a test "an order can be paid" and a test "an order can be cancelled". What happens when cancelling after shipping, nobody checked. After: one table with both allowed and forbidden transitions, and the final state is checked after each.
const transitions = [
{ from: 'created', action: 'pay', status: 200, to: 'paid' },
{ from: 'paid', action: 'ship', status: 200, to: 'shipped' },
{ from: 'created', action: 'cancel', status: 200, to: 'cancelled' },
{ from: 'shipped', action: 'cancel', status: 409, to: 'shipped' },
{ from: 'cancelled', action: 'pay', status: 409, to: 'cancelled' },
{ from: 'paid', action: 'pay', status: 409, to: 'paid' }, // no double charge
];
for (const t of transitions) {
test(t.from + ' + ' + t.action, async ({ request }) => {
const id = awaitcreateOrderInState(request, t.from); // a helperconst res = await request.post('/v1/orders/' + id + '/' + t.action);
expect(res.status()).toBe(t.status);
const order = await (await request.get('/v1/orders/' + id)).json();
expect(order.status).toBe(t.to); // state after
});
}
The helper createOrderInState prepares an order in the needed state through the API (create, pay, ship) rather than reaching into the database. The row shipped + cancel must give 409 and leave shipped: that is the "a rejection did not change the state" check. Without a state check you can miss a bug where the response is 409 but the order is already cancelled.
A CRUD chain. Create, Read, Update, Read, Delete, Read (404). Each step must see the effects of the previous one.
A repeated DELETE also needs a decision from the spec: 404 (the resource is already gone) or 204 (the end state is the same, since the operation is idempotent). Both are acceptable, the test pins what is promised.
Limits and alternatives
Dependence on order and existence. An operation on a non-existent resource (PUT /orders/999), on one already deleted, a link to a non-existent parent (POST /orders with a non-existent customerId), deleting a parent that has children (cascade or 409).
Parallel requests. Two simultaneous updates of one resource (the last wins, or a version check through If-Match fires) and a simultaneous create with the same unique value, where only one must pass:
test('two parallel creates with one unique value: only one wins', async ({ request }) => {
const data = { name: 'Olena', email: 'race-' + crypto.randomUUID() + '@test.example' };
const [a, b] = awaitPromise.all([
request.post('/v1/users', { data }),
request.post('/v1/users', { data }),
]);
expect([a.status(), b.status()].sort()).toEqual([201, 409]);
});
Pairwise is not a cure-all. It does not catch a defect that appears only with three parameters at once and knows nothing about dependencies between values. For critical combinations (money, permissions) the full product is justified.
For states with dozens of transitions, keep the table as data (an array in a file) rather than as dozens of separate tests.
Common mistakes
Testing only the happy path of states. Forbidden transitions are the source of defects: the balance changed while the order was not cancelled.
Not checking the state after a rejection. A 409 without checking that the resource did not change proves nothing yet.
Preparing the state directly in the database. The test becomes tied to the schema and bypasses the business logic it was meant to check.
One big chain for everything. When it fails on step three, the rest is unchecked and the cause is lost. Keep chains short and transitions in the table.
Check yourself
An endpoint has parameters with 4, 3 and 2 values. How many tests does the full product give, and what is the lower bound for pairwise?
Answer
The full product gives 4 × 3 × 2 = 24. For pairwise the lower bound is the product of the two largest parameters, 4 × 3 = 12, because all pairs of those two must appear. A real set may be slightly larger, the generator produces it.
A test cancels a shipped order and sees 409. What else should be checked to make the case complete?
Answer
That the order state stayed shipped (a GET after the rejection) and that side effects did not happen: no refund, the goods did not return to stock. A 409 alone does not prove the rejection was clean.
Related lessons: “Equivalence classes and boundary values for fields and parameters”, “HTTP methods, idempotency, PUT vs PATCH”, “The methods table”, “Beyond the response: side effects and system state”.
In an interview.Junior: For many parameters I use pairwise instead of the full product. For a resource with states I build a transition table and test the allowed and forbidden ones. I end a CRUD chain by checking that a deleted resource returns 404. Middle/Senior: Pairwise rests on the fact that most defects come from the interaction of two parameters, but for money and permissions I choose the full product and add dependent combinations by hand. After a rejection (409) I check that the state and side effects did not change. Parallel requests (a simultaneous create with the same unique value, an update with If-Match) are separate cases: that is where races hide.
Test data, cleanup and risk-based priorities
A test owns its data: it creates it through the API, uses it and cleans up, so the result does not depend on run order or neighbouring workers. Fields with a uniqueness constraint get unique values, access is checked with separate accounts, and cleanup runs in a finalizer so it happens even after a failure. What to test first is set by risk: the probability of a defect times its impact.
API · Test design
A suite is green in the morning and red in the evening: a test fails on the second run. Where do data come from and what comes first?
A test creates a user with the email qa@test.example. The first run is green, the second fails with 409: a user with that email already exists. A colleague runs the suite in parallel and the tests fight over the same entity. That is not an API defect, it is a test design defect: data and the order of work need design just like the cases themselves. The second question that comes with it: you cannot check everything, so where do you start.
How it works and why
There is one principle: a test owns its data. It creates what it needs through the API (or a setup step), uses it and cleans up after itself. Then the result depends only on the test code and the system, not on what is left from yesterday's run or what a neighbouring worker is doing right now.
Shared data versus own data
Typical
Shared data and order
Test B waits for the result of test A and for a permanent user from a previous run. Alone, in parallel or for the second time it fails.
Better
Data per test
Each test creates unique data, checks and cleans up. Running in any order and in parallel gives the same result.
Figure 1. An independent test is reproducible: it needs neither an order nor a clean database.
A set of rules for data follows from this:
Unique values for fields with a uniqueness constraint (a suffix from a random string), otherwise the second run fails with 409.
Separate accounts for roles (user, admin, another user): access tests need a "foreign" owner of a resource.
Permanent read-only data (reference lists, tariffs) that nobody changes.
Minimal data: only what the case needs. A production dump is not suitable, because it contains personal data.
Time and randomness are tested through fixed values or a range, not by expecting an exact "now".
Example: from a shared scenario to a fixture with cleanup
Before: two tests where the second uses the result of the first.
// two tests that depend on each other and on the previous runlet orderId: string;
test('create order', async ({ request }) => { orderId = (awaitcreate(request)).id; });
test('pay order', async ({ request }) => { awaitpay(request, orderId); });
// run "pay order" alone, or in another worker: orderId is undefined
The test "pay order" cannot be run alone, and after a change of order or on another worker orderId is empty. After: a Playwright fixture creates an order for each test and deletes it in the teardown.
import { test as base, expect } from'@playwright/test';
exportconst test = base.extend<{ order: { id: string } }>({
order: async ({ request }, use) => {
const res = await request.post('/v1/orders', { data: { sku: 'A1', quantity: 1 } });
expect(res.status()).toBe(201);
const order = await res.json();
awaituse(order); // the test runs hereconst del = await request.delete('/v1/orders/' + order.id); // runs even if the test failedexpect(del.ok(), 'cleanup must not fail silently').toBeTruthy();
},
});
test('pay own order', async ({ request, order }) => {
const res = await request.post('/v1/orders/' + order.id + '/pay');
expect(res.status()).toBe(200);
});
The code after use runs even when the test failed, so cleanup does not depend on success. A unique value for a field with a uniqueness constraint:
Cleanup can also be environmental: resetting the database before a run or a separate tenant per run. The main point is that it must not mask a defect: if DELETE does not work, a separate test should show it, not a silently swallowed error in the teardown. Leftover data from past runs is a typical cause of flaky tests, and tests that run in parallel must not share one entity.
Priorities by risk. You cannot fully check everything, so the order is set by risk: probability of a failure × consequences. The estimate is made with the team on a simple scale from 1 to 3.
Data from the API or from the database. Creating through the API also checks that very operation, but it is slower and depends on it working. Filling the database directly is faster but bypasses business logic. Often both are combined: the API for entities, the database for rare states.
Resetting the environment per run is simple when it is isolated (a container, a separate schema). In a shared environment per-test cleanup is better.
The risk scale is subjective. It is agreed with the team and reviewed after incidents: a failure that has already happened raises the probability.
High risk: money, authorization and access to other people's data, irreversible changes, new or frequently changed logic, integrations with third-party systems. Medium: the main business scenarios, search, filters, pagination. Low: rare configurations, cosmetic fields, long-stable code.
Common mistakes
One permanent user for all tests. One test changes the password, another fails, and the cause is hunted for hours.
Deleting data only at the end of a successful suite. After a failure it stays and breaks the next run.
Testing everything evenly. An hour on reference-list colours and five minutes on transfers is an inverted priority.
Catching a cleanup error with an empty catch. A delete defect disappears without a trace while garbage accumulates.
Check yourself
The test "pay an order" fails when run alone but passes as part of the whole suite. What does that mean and what should change?
Answer
The test depends on data created by another test. Make it self-sufficient: a fixture or a setup step of the same test creates the order and cleans up after it.
There are two endpoints: POST /payments (new logic) and GET /countries (stable for ages). Time is short. Which one gets deeper coverage, and why?
Answer
POST /payments. It handles money (high impact), and new logic raises the probability of a failure. The reference list /countries is stable and low risk, a positive scenario is enough.
Related lessons: “Parameter combinations, resource states and CRUD flows”, “Fixtures and scopes”, “Positive and negative cases”, “What to check when testing an endpoint”.
In an interview.Junior: Each test creates and cleans up its own data, so they can run in any order. I set priorities by risk: the probability of a failure multiplied by the consequences, and I test money, access rights and changes most deeply. Middle/Senior: Data per test and unique values make the suite reproducible and parallel. Cleanup sits in a teardown so that it runs even after a failure, but it does not swallow its own errors. Critical endpoints get the full set (classes, boundaries, negatives, states, permissions), the rest get a positive scenario and the likeliest negatives, and I review the risks after incidents.