QA & Testing · Guide

API Testing

Testing the layer under the UI — where the logic actually lives, and where contract breaks are cheapest to catch.

— min read QA & Testing

Below the Interface

API tests sit in the sweet spot: far faster and steadier than UI tests, far broader than unit tests. Most business logic is reachable there, without a browser in the way.

A thorough API test checks more than the happy path body. Status code, response shape, headers, error cases, authorisation, and what happens on a repeat call all matter — and each of them has shipped broken in production somewhere this week.

CheckTypical miss
Status codes200 with an error body inside it
Response schemaA field silently renamed or nulled
AuthorisationAnother user's id works fine
ValidationBad input accepted, or a 500 instead of a 400
IdempotencyA retried POST charges twice
PaginationPage 2 repeats items from page 1

Contract Testing

Two services agree on a shape. One team changes it. Nothing fails until production, because each service's own tests pass against its own idea of the contract. Contract testing closes that gap without standing up both systems together.

SideWhat it verifies
ConsumerRecords the requests it makes and the responses it needs
ProviderReplays those expectations against the real implementation
BrokerShares contracts between the two, versioned per deploy

The payoff is that a provider learns it is about to break a consumer before deploying, in a fast test rather than an integration environment. It is the cheapest defence against the failure mode microservices are most prone to.

A schema definition — OpenAPI, JSON Schema — is worth validating responses against in ordinary tests too. It turns "the docs are out of date" from a recurring complaint into a failing build.

Postman & REST Clients

Exploring an API by hand is how you learn what it really does. A GUI client is right for discovery; a scripted runner is right for anything you intend to repeat.

ToolBest at
Postman / InsomniaExploration, collections, sharing with the team
curl / HTTPieOne-off checks and pasting into a bug report
REST Client files in the repoRequests versioned alongside the code
Code-level clientsThe real suite — assertions, fixtures, CI
# a bug report with this in it is reproducible by anyone
curl -i -X POST https://api.example.com/v1/orders \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"sku":"ABC-1","qty":0}'

# expected 400 with {"error":"qty must be positive"} — actual 500
A Postman collection is a fine artefact and a poor test suite: it drifts from the code, hides in one person's account, and is awkward to review. Once a check matters, move it into the repository where it runs on every commit.

Interview Questions

Why test at the API layer?

It is far faster and more stable than the UI and much broader than unit tests. Most business logic is reachable there without a browser, so it gives the best information per second of runtime.

What should an API test assert beyond the body?

Status code, response schema, headers, error cases, authorisation, idempotency on retry and pagination behaviour — each is a common production defect.

What problem does contract testing solve?

Two services agreeing on a shape that one of them changes. Each side's own tests keep passing, and it only breaks in production. Contract tests verify the agreement without running both systems together.

How does consumer-driven contract testing work?

The consumer records the requests it makes and the responses it needs; the provider replays those expectations against its real implementation, so it learns it is about to break someone before deploying.

Why validate responses against a schema?

It catches silently renamed or nulled fields and keeps the published API definition honest — the docs failing the build rather than quietly going stale.

Is a Postman collection a test suite?

It is good for exploration and sharing, but it drifts from the code, lives outside version control and is hard to review. Checks that matter belong in the repository, running on every commit.

Quick Quiz

1. API tests sit between unit and UI tests because they are…
2. A retried POST that charges twice is a failure of…
3. Consumer-driven contract testing verifies…
4. Returning 200 with an error body inside is caught by asserting…
5. Checks that matter long-term belong…