- All Courses
- API Design with Node.js
- Quality and Delivery
- Testing an API
Testing an API
Unit tests on handlers miss routing, middleware, serialisation, and status codes — which is where API bugs live.
Overview
Test what the client actually calls
Unit tests on handlers miss routing, middleware, serialisation, and status codes — which is where API bugs live. Tests that make real requests through the whole stack catch them.
The error paths deserve as much coverage as the happy path: unauthenticated, unauthorised, malformed body, missing resource, conflict. These are the responses clients handle most often and that break most silently.
Tests that depend on execution order or on data another test created fail mysteriously and get deleted. Each test should set up what it needs.
In this lesson you will:
- Test at the HTTP boundary
- Cover auth and error paths
- Keep tests independent of each other
Resources
Notes are not saved yet — they clear when you leave this page.
Documenting with OpenAPI
5m
Logging, tracing, and health checks
38m