Short answer
Negative tests check that an API correctly rejects bad requests: missing fields, wrong format, a missing or expired token, access to someone else’s resource, a duplicate, a repeated request and an exceeded rate limit. The 15 scenarios below cover most of the bugs that come up in API testing. In each one you check three things: the response code (400, 401, 403, 404, 409, 422 or 429), a clear error message and that nothing changed in the data.
15 negative scenarios
The examples use a POST /orders endpoint that creates an order.
Data validation
| # | scenario | example | expected result |
|---|---|---|---|
| 1 | missing required field | request without productId | 400 or 422, field name in the message |
| 2 | wrong data type | "quantity": "two" | 400 or 422 |
| 3 | boundary values | quantity equal to 0, -1 and above the limit | 422 for out-of-range values, 201 for allowed boundaries |
| 4 | long text and special characters | 10,000 characters, emoji, non-ASCII letters in the name | 422 or saved without truncation or changed characters |
| 5 | wrong format | email without @, date 2026-02-30 | 422 |
| 6 | broken JSON or wrong header | cut-off bracket, Content-Type: text/plain | 400 or 415 |
Access
| # | scenario | example | expected result |
|---|---|---|---|
| 7 | no token | request without the Authorization header | 401 |
| 8 | expired or altered token | an hour-old token, one character changed | 401 |
| 9 | someone else’s resource | GET /orders/{id} of another user’s order | 403 or 404, no order data |
| 10 | role without permissions | a regular customer calls an admin endpoint | 403 |
State and logic
| # | scenario | example | expected result |
|---|---|---|---|
| 11 | non-existent resource | GET /orders/999999 | 404 |
| 12 | duplicate | signing up a second time with the same email | 409 |
| 13 | repeated request | the same POST /payments twice with the same idempotency key | one payment, second response the same as the first |
| 14 | forbidden state change | cancelling an order that has already shipped | 409 or 422 |
| 15 | rate limit | 100 requests per second from one account | 429 and a Retry-After header |
Scenarios 7-10 are a basic access check as part of functional testing. They don’t replace security testing or penetration testing.
What to check in every error response
- Response code in line with the API contract.
- Error structure the same across the whole API, e.g. in the Problem Details format (RFC 9457): type, title, detail, list of invalid fields.
- No technical details: no stack trace, SQL queries or server names.
- No data changes: after a rejected
POST, a followingGETdoesn’t show a new order. - No side effects: no email went out, no stock was reserved, no card was charged.
The last two points are skipped most often, and they are the ones that protect against the most expensive bugs. I cover retried payment notifications in the guide testing webhooks and payments.
A test example in Postman
A test for scenario 1, in the request’s Tests tab:
pm.test("422 when productId is missing", () => {
pm.response.to.have.status(422);
const body = pm.response.json();
pm.expect(JSON.stringify(body)).to.include("productId");
});
pm.test("no stack trace in the response", () => {
pm.expect(pm.response.text()).to.not.include("at com.");
});
You can run the collection in CI with Newman. I cover the basics of requests, response codes and Postman in API testing basics. When to choose Postman and when RestAssured is covered in Postman vs RestAssured.
Consistency with the contract
Whether a validation error is 400 or 422 depends on the team’s convention. What matters is that there is one, and that it’s described in the contract, e.g. in OpenAPI. Then negative tests check compliance with the contract, and a change to the error format in one service won’t silently break the mobile app. How to keep the contract between services in check is covered in API contract testing.
How I can help
As part of API testing I prepare a suite of 50-80 cases in Postman or RestAssured, with these negative scenarios for your endpoints and CI runs. It usually costs PLN 10,000-15,000 net and takes 2-3 weeks. Describe your API and the documentation you have in the contact form.