agentleFS
WST2002WST2002/claude-code-skills/skills/api-test-writer/SKILL.md

api-test-writer

Skill4 starsChanged 27 days agoMITView on GitHub

Use when writing automated API tests or integration tests for REST or GraphQL endpoints, testing from an OpenAPI/Swagger spec or Postman collection, or checking status codes, response schemas, auth and error handling — Supertest, pytest + httpx, REST Assured, Postman/Newman and others.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Control data: create what each test needs through the API or factories, clean up afterwards, use unique values to allow parallel runs.

    line 17
  2. Distinctive:

    Only testing the happy path.

    line 69
  3. Distinctive:

    Never testing authorization with a second user.

    line 72

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Test Writer

Overview

API tests check the contract clients depend on: status codes, response shape, validation, authorization and side effects. They are faster and more stable than UI tests, so most functional coverage belongs here.

Method

  1. Inventory the endpoints from routes, controllers or the OpenAPI spec: method, path, auth, request schema, responses.
  2. Match the project's tooling: existing test framework and HTTP client (Supertest for Node, httpx/requests with pytest, REST Assured for Java, Newman for Postman collections). Follow existing test structure.
  3. Write cases per endpoint using the matrix below.
  4. Control data: create what each test needs through the API or factories, clean up afterwards, use unique values to allow parallel runs.
  5. Run the suite and confirm each new test fails when the behavior is broken (change an expected value once to check).

Case matrix per endpoint

CategoryCases
SuccessValid request → correct status (200/201/204), body matches schema, headers (Location, Content-Type)
ValidationMissing required field, wrong type, out-of-range, too long, invalid format → 400/422 with field-level errors
AuthenticationNo token, expired token, malformed token → 401
AuthorizationOther user's resource (IDOR), insufficient role → 403 or 404
Not foundUnknown ID → 404 with the standard error shape
ConflictsDuplicate unique value, stale version → 409
Side effectsRecord created/updated in the database, event or email queued, idempotent retry does not duplicate
ListsPagination, filters, sorting, empty results, max page size

Example (Node, Supertest + Vitest)

import request from "supertest";
import { describe, it, expect } from "vitest";
import { app } from "../src/app";
import { createUser, tokenFor } from "./factories";

describe("POST /orders", () => {
  it("creates an order and returns 201 with a Location header", async () => {
    const user = await createUser();
    const res = await request(app)
      .post("/orders")
      .set("Authorization", `Bearer ${tokenFor(user)}`)
      .send({ items: [{ sku: "SKU-1", quantity: 2 }] });

    expect(res.status).toBe(201);
    expect(res.headers.location).toMatch(/^\/orders\/\w+$/);
    expect(res.body).toMatchObject({ status: "pending", items: [{ sku: "SKU-1", quantity: 2 }] });
  });

  it("rejects quantity 0 with a field error", async () => {
    const user = await createUser();
    const res = await request(app)
      .post("/orders")
      .set("Authorization", `Bearer ${tokenFor(user)}`)
      .send({ items: [{ sku: "SKU-1", quantity: 0 }] });

    expect(res.status).toBe(422);
    expect(res.body.errors).toContainEqual(expect.objectContaining({ field: "items[0].quantity" }));
  });
});

Common mistakes

  • Only testing the happy path.
  • Asserting the whole response with a snapshot that includes IDs and timestamps.
  • Tests that depend on data created by another test.
  • Never testing authorization with a second user.
  • Hitting production or shared environments with destructive tests.

Made by Wageesha Tripathi · LinkedIn · Email · More skills

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.