Mercury SkillsMercury Skills
v1.0.0 cosmicstack-labs

API Testing

REST and GraphQL testing, Postman/Insomnia patterns, contract testing, schema validation, and monitoring

View source0 downloads
apitestingrestgraphqlcontract-testing

API Testing#

Test REST and GraphQL APIs systematically.

Test Categories#

CategoryWhatExample
FunctionalDoes it work?POST /users returns 201
ValidationInput handlingMissing required field → 400
AuthAccess controlNo token → 401
Edge CasesBoundary conditionsMax page size, empty results
ContractSchema conformanceResponse matches OpenAPI spec
PerformanceWithin SLOp95 < 500ms

REST API Testing#

Structure#

describe('POST /users', () => {
  it('creates a user with valid data', async () => {
    const res = await request(app)
      .post('/api/users')
      .send({ name: 'Alice', email: 'alice@test.com' });
    expect(res.status).toBe(201);
    expect(res.body).toHaveProperty('id');
  });
  it('rejects duplicate email', async () => {
    const res = await request(app)
      .post('/api/users')
      .send({ name: 'Alice', email: 'existing@test.com' });
    expect(res.status).toBe(409);
  });
});

Contract Testing (Pact)#

  • Provider publishes OpenAPI spec
  • Consumer tests verify against published spec
  • CI rejects PR if contract breaks
  • Prevents API drift between services

GraphQL Testing#

  • Test queries and mutations independently
  • Validate against schema
  • Test error paths (partial failures, null propagation)

API Monitoring#

  • Synthetic checks every 5 minutes
  • Assert status, response time, required fields
  • Alert on SLA breaches
  • Monitor from multiple regions

More in Testing & QA

View all →