API Integration Testing
Build robust test suites for your APIs with integration, contract, and E2E tests.
Testing Pyramid for APIs
Level What It Tests Speed Isolation
Unit Handlers, validators, utils Fast High
Integration API + database, services Medium Medium
Contract API shape vs OpenAPI spec Fast High
E2E Full stack, real DB Slow Low
Key Principles
-
Test API behavior through HTTP requests, not internal function calls
-
Use real database for integration tests (SQLite or test containers)
-
Validate response shapes against OpenAPI spec with contract tests
-
Isolate external services with MSW or similar mock servers
Quick Start Checklist
-
Set up test framework (Vitest + Supertest recommended)
-
Configure test database (separate from dev)
-
Create test factories for data setup
-
Write integration tests for each endpoint (happy + error paths)
-
Add contract tests against OpenAPI spec
-
Configure CI pipeline for automated test runs
References
Reference Description
test-frameworks.md Vitest, Jest, Supertest setup and configuration
test-patterns.md Request testing, authentication, error validation
test-data.md Factories, fixtures, database seeding
contract-testing.md OpenAPI validation, schema testing
ci-cd.md CI pipeline configuration, environment setup