Testing fundamentals

API Testing Strategies: What to Test at Each Layer

Hasan KhanHasan Khan 12 min read
API testing strategies by layer: contract, functional, chained workflow, security and load checks on an API

The release went out on Friday. The orders API still returned 200, every field was still there, and the contract tests were green. On Monday, support found that any signed-in customer could read any other customer's orders by changing the ID in the URL.

Nobody had skipped testing. They had tested one layer very well and assumed the others were covered. An API testing strategy is the plan that stops that assumption from reaching production.

A good API testing strategy tests each layer for the failures it is best at catching: contracts and schemas for breaking changes, functional and chained tests for behaviour, auth and negative tests for abuse, performance tests for load, and a few API plus UI journeys for the full picture. Run the fast layers on every pull request and the slow ones on a schedule.

Key takeaways

  • Treat API testing as layers, each with its own job. No single layer catches everything.
  • Most damaging API bugs sit between calls or between users, so chained workflows and authorisation tests deserve priority.
  • Prioritise by risk: money, personal data and the endpoints your clients use most come first.
  • Match each layer to a CI stage. Contract and smoke checks on every pull request, full suites on merge, load before releases.

What is an API testing strategy?

An API testing strategy decides what you test, at which layer, in what order, and where each test runs. It is not a list of test cases. It is the reasoning that tells a team which tests to write next and which ones can wait.

A strategy answers four questions. Which failures would hurt us most? Which layer catches each failure cheapest? Who owns each layer? And when in the pipeline does each layer run?

If you are new to API testing itself, start with our API testing guide, which covers requests, methods and assertions. This post assumes you know how to write a test and need to decide which tests to write.

What are the layers of API testing?

Each layer targets a different kind of failure. The table maps them before we look at each in turn.

LayerWhat it catchesExample checkTypical speed
Contract and schemaBreaking changes in structurerefundStatus still exists and is a stringSeconds
FunctionalWrong behaviour on one endpointCreating an order returns the right totalSeconds
Chained workflowsBroken hand-offs between callsLogin token reaches the payment callSeconds to minutes
Auth and securityAccess the caller shouldn't haveUser A can't read user B's orderSeconds
Negative and errorPoor handling of bad inputA missing field returns 400 with a clear messageSeconds
PerformanceSlowdowns and failures under loadCheckout holds up at peak trafficMinutes to hours
Data and stateSide effects and leftoversA refund updates the balance once, not twiceSeconds to minutes
API plus UI end-to-endGaps between backend and screenAPI saves a record and the screen shows itMinutes

Lower layers are fast, cheap and precise. Higher layers are slower but closer to what users experience. A balanced strategy has many tests at the bottom and a deliberate few at the top.

How do you test API contracts and schemas?

Contract tests check that an API's shape matches what its clients expect: field names, types, required fields and status codes. They catch the renamed field, the integer that became a string, and the endpoint that quietly stopped returning currency.

There are two common approaches:

  • Schema validation against your OpenAPI definition. Every response is checked against the documented structure. This works well when one team owns both the API and its spec.
  • Consumer-driven contracts. Each client records what it actually uses, and the provider verifies it can still satisfy those expectations. Pact describes itself as a code-first tool for testing HTTP and message integrations with contract tests, where contracts are generated during the consumer's tests.

Contract tests are the cheapest insurance against breaking changes. Run them whenever the API or its definition changes, and before any client team deploys.

What should functional API tests check?

Functional tests check that a single endpoint does the right thing with valid input. They are the layer most teams start with, and where most API test automation suites begin.

For each endpoint, a functional test should cover:

  • Status code for the expected case, such as 201 for a created resource.
  • Key body fields and values, not just that the body exists. Check the total, the status and the ID that matters.
  • Headers that clients depend on, such as content type or pagination links.
  • Business rules, such as a discount applied only above a threshold.

Avoid asserting on every field in every test. That turns functional tests into brittle contract tests. Check what this test is about, and leave structure to the contract layer.

Why test chained API workflows?

Real clients never call one endpoint. They sign in, create a cart, add items, pay and check the order status. Each call depends on values from the one before, and that is where many API bugs live.

A chained workflow test passes values from one response into the next request, with assertions at every step. A typical chain looks like this:

  1. Authenticate and store the token.
  2. Create a resource and store its ID.
  3. Read it back and check the stored values.
  4. Update it and check the change.
  5. Delete it and confirm a follow-up read returns 404.

Chained tests catch the token that never reaches the payment call, the ID format that one service changed, and the update that succeeds but isn't saved. Our integration testing guide covers the same idea across services.

How do you test API authentication and security?

Authentication tests check that the API knows who is calling. Authorisation tests check that each caller can only do what they're allowed to. The opening example was an authorisation failure, and it is a common one.

The OWASP API Security Top 10 (2023) puts Broken Object Level Authorization first, ahead of Broken Authentication. It also lists Broken Object Property Level Authorization, Unrestricted Resource Consumption and Broken Function Level Authorization, among others. These make a useful checklist for this layer.

Practical tests for most APIs:

  • No credentials: every protected endpoint returns 401.
  • Wrong user: user A requesting user B's resource gets 403 or 404, never the data.
  • Wrong role: a standard user calling an admin endpoint is refused.
  • Hidden fields: a user can't set fields such as role or price by adding them to the request body.
  • Expired or revoked tokens are rejected.

Keep test credentials in your CI secret store or a vault, never in the tests. Security testing tools go further, but these checks belong in the regular suite because they are cheap and catch real breaches.

What negative and error cases should API tests cover?

Negative tests send input the API should reject and check that it fails safely and clearly. A good API returns the right 4xx code, a message a client can act on, and no stack trace.

Cover these cases for important endpoints:

CaseExpected result
Missing required field400 with the field named
Wrong type, such as text for a number400, not 500
Value out of range, such as a negative quantity400 or 422
Unknown resource ID404
Duplicate create409, or the documented behaviour
Too many requests429 if rate limiting is in place
Oversized payloadA clear rejection, not a timeout

Any 500 from bad input is a bug. A simple rule for this layer is that the client, not the server, should be blamed in the response.

Where does API performance testing fit?

Performance tests check how the API behaves under load: response times, error rates and throughput as virtual users increase. They answer a different question from functional tests, so keep them separate.

Common types are load tests at expected traffic, stress tests beyond it, spike tests for sudden bursts and soak tests over hours. Grafana k6, for example, supports HTTP/1.1, HTTP/2, WebSockets and gRPC out of the box.

Performance tests are slow and need a production-like environment, so they rarely run on every pull request. Run them on a schedule and before big releases. Our guide to web app load testing covers planning a load test, and performance testing shows how Robonito handles it.

How do you handle test data and state in API tests?

APIs change data, so every test leaves something behind unless you plan for it. Flaky API suites often trace back to shared data, not to the API itself.

A sound data strategy follows a few rules:

  • Each test creates what it needs. Don't depend on a record someone created by hand last month.
  • Clean up after yourself, or use disposable environments that reset between runs.
  • Use unique values, such as a timestamp in an email address, so parallel runs don't collide.
  • Check side effects, not just the response. A refund should change the balance exactly once.

Where a response can't prove a side effect, check the data store directly. Our database testing guide covers those checks.

When do you need API and UI end-to-end tests?

Some failures only show up when the backend and the screen meet. The API saves the new address, but the web app still shows the old one. The mobile app reads a field the API stopped sending.

API plus UI tests combine both in one journey. Create data through the API, then check the screen. Or act on the screen, then check the API state. Using the API for setup also makes UI tests faster and less flaky than clicking through every step.

Keep this layer small. Pick the handful of journeys where a gap between backend and screen would hurt most, such as checkout, refunds and account changes. Our guide on end-to-end testing tools covers the build-or-buy choice for this layer.

How do you prioritise API tests?

You can't test every endpoint at every layer at once. Score endpoints by risk and work down the list.

  1. List your endpoints from the OpenAPI definition or gateway logs.
  2. Score impact: does a failure lose money, expose personal data, block sign-in or break a partner integration?
  3. Score usage: which endpoints do clients call most, and which do mobile apps depend on?
  4. Score change rate: which code changes most often?
  5. Start with the top ten and give each a contract check, a functional test, an authorisation test and the key negative cases.
  6. Add chained workflows for the three to five journeys that matter most.
  7. Add performance tests for endpoints with high traffic or strict response-time needs.

This gives broad, shallow coverage first, then depth where risk is highest. Revisit the scores each quarter, because the risky parts of an API move.

Where does each API test layer run in CI?

API tests need no browser or device, so they are the cheapest automated tests to run often. The trick is putting each layer where its speed and value fit.

Pipeline stageLayers to runGoal
Every pull requestContract checks, smoke functional tests, critical auth testsFast feedback, under a few minutes
Merge to mainFull functional, negative and chained suitesCatch regressions before deploy
After deploy to stagingAPI plus UI journeys, data checksConfirm the environment works end to end
NightlyEverything above, plus long chainsCatch slow or intermittent failures
Before major releasesLoad, stress and soak testsConfirm capacity

Fail the build on broken contracts and critical endpoints. Send other failures to the team's chat channel with the request, response and failing assertion. Our continuous integration post and CI/CD test automation page cover pipeline set-up.

Which tools fit each layer of an API test automation framework?

An API test automation framework is the structure that holds these layers together: environments, secrets, shared setup, data handling and reporting. Most teams use more than one tool to cover every layer.

LayerTool types that fitExamples
Contract and schemaContract testing tools, OpenAPI validatorsPact
Functional, negative, authAPI test frameworks and platformsPostman, REST Assured, Karate, Robonito
Chained workflowsFrameworks with variable passing, or no-code platformsKarate, Postman, Robonito
PerformanceLoad testing toolsk6, JMeter, Gatling
API plus UIBrowser frameworks with API support, or platforms that mix bothPlaywright, Robonito

Playwright's API testing docs describe using its request context to set up state before a UI test and check server-side results after a browser action. For a full comparison with pricing, see our list of the best API test automation tools.

API testing strategy with Robonito

Robonito is an agentic QA platform: AI agents create, run and maintain end-to-end tests. API testing is on the Pro and Enterprise plans, and it covers several layers of the strategy above.

  • Functional, negative and auth tests without code. Send REST requests and check status codes, fields and values at each step from a no-code test case. Add a script only when a step needs custom logic.
  • Chained workflows. Pass values from one response into the next request, so a test can sign in, create an order and confirm it the way a real client would.
  • API plus UI in one journey. Create data through the API and confirm it on screen in the same test, or the reverse.
  • Start from what you have. Import existing Postman collections, or let AI Studio generate API tests from Swagger or OpenAPI definitions.
  • CI and evidence. Trigger suites from Jenkins, GitHub Actions, GitLab CI, Azure DevOps or CircleCI, or on a schedule. Each run keeps a step-by-step request log, network traces and an AI root cause for failures.
  • Performance. Load testing is on Pro and Enterprise, at $0.04 per virtual-user hour on the rate card.

Pricing. Pro is $199 a month ($159.20 billed annually), with $250 of cloud usage, 10 parallel runs and unlimited test cases. Beyond that, API runs cost $0.01 a minute and load testing $0.04 per virtual-user hour. See pricing.

Where it doesn't fit. API testing isn't on the Free or Starter plans. For consumer-driven contract testing between services, a dedicated tool such as Pact fits better. If developers want API tests in the repository as code, REST Assured, Karate or Playwright suit that workflow. And if you test GraphQL, gRPC, SOAP or a specific auth scheme, confirm your protocols in a demo before you commit.

and bring a Postman collection or an OpenAPI file, or on web tests first.

Frequently asked questions

What are the main API testing strategies?

The main strategies are layered: contract and schema tests for breaking changes, functional tests for single endpoints, chained workflow tests for multi-step journeys, auth and security tests for access control, negative tests for bad input, performance tests for load, data and state checks for side effects, and a few API plus UI tests for end-to-end coverage.

Which API tests should run on every pull request?

Run the fast, high-value checks: contract or schema validation, a smoke set of functional tests on critical endpoints, and the key authorisation tests. Together they should finish in a few minutes. Leave full chained suites for merge, API plus UI journeys for staging, and load tests for a schedule or before major releases.

What is an API test automation framework?

It is the structure around your API tests that keeps them maintainable: environment configuration, secrets handling, shared authentication and setup, test data and clean-up, chained flows and reporting. You can build one in code around a library such as REST Assured or Playwright, or use the built-in structure of a platform such as Postman, Karate or Robonito.

How is contract testing different from functional API testing?

Contract testing checks the shape of requests and responses, such as field names, types and required fields, so clients don't break when the API changes. Functional testing checks behaviour, such as whether an order total is correct. A response can match its contract and still be wrong, so you need both layers.

How do you prioritise which API endpoints to test first?

Score each endpoint on impact, usage and how often its code changes. Endpoints that handle money, personal data, sign-in or partner integrations come first. Give the top ten a contract check, a functional test, an authorisation test and key negative cases, then add chained workflows for your most important journeys.

Should API tests and UI tests be separate?

Mostly, yes. API tests are faster and more precise, so most coverage should sit there. But keep a small set of API plus UI journeys for features where the backend and screen must agree, such as checkout or account changes. Using API calls for setup inside UI tests also makes those UI tests faster and more stable.


Turn your API testing strategy into a suite that runs on every change. to see chained API and UI tests on your own endpoints, or .

Free whitepaperThe Agentic QA PlaybookMove from test scripts to AI agents in 90 days, with the controls, metrics and a 25-question vendor checklist.

No-code AI test automation

Spend less time testing and more time shipping.

3Pillar showed Robonito's agents to its own client live, and that client is now onboarding. Start on the Free plan, which stays free forever, or book a demo and we'll walk through your own app.

All blog posts