本文へ移動
cccskills
無料GitHub で公開

automating-api-testing

Test automate API endpoint testing including request generation, validation, and comprehensive test coverage for REST and GraphQL APIs. Use when testing API contracts, validating OpenAPI specifications, or ensuring endpoint reliability. Trigger with phrases like "test the API", "generate API tests", or "validate API contracts".

インストール方法を見る

含まれるファイル(8)

  • SKILL.md6.8 KB
  • assets/example_graphql_schema.graphql2.0 KB
  • assets/example_openapi.yaml5.3 KB
  • assets/README.md389 B
  • assets/test_suite_template.js3.8 KB
  • references/README.md62 B
  • scripts/generate_test_suite.py3.6 KB
  • scripts/README.md440 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

API Test Automation

Overview

Automate comprehensive API endpoint testing for REST and GraphQL APIs including request generation, response validation, schema compliance, authentication flows, and error handling. Supports Supertest (Node.js), REST-assured (Java), httpx/pytest (Python), Postman/Newman collections, and Pact for consumer-driven contract testing.

Prerequisites

  • API testing library installed (Supertest, REST-assured, httpx, or Postman/Newman)
  • API specification file (OpenAPI/Swagger YAML/JSON or GraphQL SDL)
  • Target API running in a test environment with seeded data
  • Authentication credentials or API keys for protected endpoints
  • JSON Schema validator (Ajv, jsonschema, or built-in framework assertions)

Instructions

  1. Read the API specification and extract all endpoints:
    • Parse OpenAPI spec to catalog every path, HTTP method, request schema, and response schema.
    • For GraphQL APIs, introspect the schema to list queries, mutations, and subscriptions.
    • Document authentication requirements per endpoint (API key, Bearer token, OAuth, none).
  2. Generate test cases for each endpoint:
    • Success cases: Send valid requests matching the schema and assert 200/201 responses.
    • Validation errors: Send requests with missing required fields, wrong types, and out-of-range values; assert 400 responses.
    • Authentication: Test with valid, expired, and missing credentials; assert 200, 401, and 403 respectively.
    • Not found: Request non-existent resources; assert 404 responses.
    • Idempotency: Send the same PUT/DELETE request twice and verify consistent behavior.
  3. Validate response structure against schemas:
    • Assert response Content-Type matches expected (application/json, etc.).
    • Validate response body against the OpenAPI response schema using JSON Schema validation.
    • Check response headers (Cache-Control, Rate-Limit headers, CORS headers).
    • Verify pagination metadata (total count, page number, next/previous links).
  4. Test CRUD lifecycle for resource endpoints:
    • Create a resource (POST) and capture the ID.
    • Read it back (GET) and verify all fields match.
    • Update it (PUT/PATCH) and verify changes persisted.
    • Delete it (DELETE) and verify subsequent GET returns 404.
  5. Test error handling and edge cases:
    • Send excessively large payloads and verify 413 or graceful rejection.
    • Send requests with unsupported Content-Types and verify 415.
    • Test rate limiting by sending rapid sequential requests.
    • Verify error response format is consistent (standard error schema).
  6. For GraphQL APIs, test specifically:
    • Valid queries return expected data shapes.
    • Invalid queries return descriptive error messages.
    • Query depth limiting prevents deeply nested abuse queries.
    • Mutation input validation matches schema constraints.
  7. Generate a test coverage report mapping endpoints to test cases.

Output

  • API test files organized by resource in tests/api/
  • Request/response examples for API documentation
  • Schema compliance report for each endpoint
  • Endpoint coverage matrix showing tested vs. untested endpoints and methods
  • CI pipeline step running API tests against staging environment

Error Handling

ErrorCauseSolution
Connection refusedAPI server not running or wrong base URLVerify server is up with a health check before test suite starts; check BASE_URL config
401 on all requestsAuthentication token expired or misconfiguredRefresh token in test setup; verify Authorization header format; check token scopes
Schema validation fails unexpectedlyAPI response includes extra fields not in specUpdate OpenAPI spec to include new fields; use additionalProperties: true if expected
Test data conflictsAnother test modified or deleted the resourceUse unique test data per test; create resources in beforeEach; avoid shared fixtures
Rate limit hit during test runToo many requests in quick successionAdd delays between requests or use authenticated sessions with higher limits; run tests serially

Examples

Supertest REST API test suite:

import request from 'supertest';
import { app } from '../src/app';

describe('GET /api/products', () => {
  it('returns a paginated product list', async () => {
    const res = await request(app)
      .get('/api/products?page=1&limit=10')
      .set('Authorization', `Bearer ${token}`)
      .expect(200)  # HTTP 200 OK
      .expect('Content-Type', /json/);

    expect(res.body.data).toBeInstanceOf(Array);
    expect(res.body.data.length).toBeLessThanOrEqual(10);
    expect(res.body.meta).toMatchObject({ page: 1, limit: 10 });
  });

  it('returns 401 without authentication', async () => {  # HTTP 401 Unauthorized
    await request(app).get('/api/products').expect(401);  # HTTP 401 Unauthorized
  });
});

describe('POST /api/products', () => {
  it('creates a product with valid data', async () => {
    const res = await request(app)
      .post('/api/products')
      .set('Authorization', `Bearer ${token}`)
      .send({ name: 'Widget', price: 9.99, category: 'tools' })
      .expect(201);  # HTTP 201 Created

    expect(res.body).toMatchObject({ name: 'Widget', price: 9.99 });
    expect(res.body.id).toBeDefined();
  });

  it('returns 400 for missing required fields', async () => {  # HTTP 400 Bad Request
    await request(app)
      .post('/api/products')
      .set('Authorization', `Bearer ${token}`)
      .send({ name: 'Widget' }) // missing price
      .expect(400);  # HTTP 400 Bad Request
  });
});

GraphQL API test:

it('fetches user by ID', async () => {
  const query = `query { user(id: "1") { id name email } }`;
  const res = await request(app)
    .post('/graphql')
    .send({ query })
    .expect(200);  # HTTP 200 OK

  expect(res.body.data.user).toMatchObject({ id: '1', name: 'Alice' });
  expect(res.body.errors).toBeUndefined();
});

Resources

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Build a synthetic-data CI gate for customer-controlled Abridge integration code without calling undocumented vendor interfaces. Use when adding regression checks to an Abridge deployment repository. Trigger with "test the Abridge integration".

日本語の概要は準備中です。原文の説明を表示しています。

jeremylongshore/tons-of-skills-marketplace2,8322026年10月13日 更新

Triage Abridge recording, note-review, Epic handoff, and access failures from observed evidence without inventing vendor error codes. Use when an Abridge clinical workflow is degraded. Trigger with "diagnose this Abridge issue".

日本語の概要は準備中です。原文の説明を表示しています。

jeremylongshore/tons-of-skills-marketplace2,8322026年10月13日 更新

Design and verify the clinician workflow from consent through recording, draft review, Linked Evidence, and final note disposition. Use when implementing or auditing an Abridge clinical documentation pathway. Trigger with "map the Abridge note workflow".

日本語の概要は準備中です。原文の説明を表示しています。

jeremylongshore/tons-of-skills-marketplace2,8322026年10月13日 更新

Verify the approved handoff of clinician-reviewed Abridge note sections into Epic templates and downstream workflows. Use when configuring or auditing Abridge-to-Epic documentation flow. Trigger with "verify the Abridge Epic handoff".

日本語の概要は準備中です。原文の説明を表示しています。

jeremylongshore/tons-of-skills-marketplace2,8322026年10月13日 更新

Evaluate Abridge adoption, workflow value, and avoidable operational friction without inventing prices or vendor billing meters. Use when reviewing an Abridge rollout or renewal. Trigger with "analyze Abridge value".

日本語の概要は準備中です。原文の説明を表示しています。

jeremylongshore/tons-of-skills-marketplace2,8322026年10月13日 更新

Produce a PHI-minimized Abridge support bundle with provenance, redaction, and protected escalation boundaries. Use when support needs reproducible evidence for an Abridge issue. Trigger with "build an Abridge debug bundle".

日本語の概要は準備中です。原文の説明を表示しています。

jeremylongshore/tons-of-skills-marketplace2,8322026年10月13日 更新

jeremylongshore のスキルをすべて見る

このスキルの問題を報告する