API Testing / Intermediate: interacting contracts / Lesson 14
Account for identities across API pages
Verify ordered record identities and cursor scope with a controlled synthetic dataset.
On this page
Lesson goals
- State ordering and consistency assumptions.
- Compare page identities with an independent expected sequence.
- Separate provider and client merge evidence.
Define the pagination contract
A paginated API needs a documented ordering, cursor scope and consistency model. A test cannot assume a snapshot if the contract permits records to change between requests. In this fictional isolated lab, a fixed synthetic dataset has four records and an agreed stable order. Define the expected sequence independently before requesting pages. Record the provider revision, filter, page size and cursor sequence so a failure can be reproduced without exposing real records or credentials.
Prepare a discriminating fixture
Create distinct synthetic identifiers and include equal primary sort values to test the documented tie-breaker. The first table illustrates two pages for the simple fixed dataset; it does not claim that a request was executed. Calculate the expected identity sequence from the agreed order rather than copying page responses. Include a final partial page in a separate fixture. A correct total count is not enough: one duplicate and one missing record can cancel numerically.
Page | Returned identities
1 | A, B
2 | C, D
The table describes expected identities and does not claim a request was executed.
Follow cursors and compare identities
Request the first page and follow each returned cursor using the same filter and ordering required by the contract. Preserve the raw safe responses and compare every identity with the independent expected sequence. The second table describes the fixed lab expectation. Verify the clientโs collected list against the raw pages to distinguish a provider ordering issue from a client merge defect. Record the first divergent page and cursor rather than reporting only the final count.
Check | Expected
collected identities | A, B, C, D
repeated identity | none for static lab dataset
The table describes expected identities and does not claim a request was executed.
Separate static and changing data
Run the static fixture without concurrent changes first. If the API specifies behavior when data changes between pages, exercise that behavior in a separate controlled case and state its expected result. Do not label permitted differences as defects or invent guarantees about a snapshot. A cursor may be scoped to a particular query; test changes to filter or sort only according to documented semantics. Use an authorized isolated service and synthetic records throughout.
Verify and record the result
After a correction, repeat the original fixture with a second page size and compare the full sequence, missing identities and duplicates. Verify a normal allowed query alongside any documented invalid cursor case. Record the raw page evidence, service revision, contract assumptions and untested concurrency conditions. These observations support the selected datasets and requests; they cannot establish correct pagination for every dataset, client or concurrent schedule.
Common errors and fixes
Checking only the total record count
- Why it happens
- A missing record and duplicate can cancel.
- How to fix it
- Compare every returned identity with the expected sequence.
- Prevent it next time
- Use fixtures with distinct identifiers.
Assuming snapshot behavior without a contract
- Why it happens
- Concurrent changes can have documented effects.
- How to fix it
- Review the stated consistency model.
- Prevent it next time
- Test static and changing data separately.
Blaming the provider before examining raw pages
- Why it happens
- A client merge can alter otherwise correct responses.
- How to fix it
- Compare raw responses with the collected list.
- Prevent it next time
- Preserve page-level evidence and cursors.
2 practice exercises
1. Four records are collected but A appears twice and D is missing. Does the total establish correctness?
Show worked solution
No. The identity sequence is wrong despite the count. Compare raw pages, order and client merge with the contract.
2. Records change during pagination but the contract does not promise a snapshot. What should the test report?
Show worked solution
Record the changes and apply the documented semantics; do not assert a snapshot guarantee that the API does not promise.
Key takeaways
- Check identities and ordering, not just totals.
- State cursor scope and consistency assumptions.