Test an API Endpoint
Workflow for writing comprehensive API endpoint tests
CLAUDE.md
When testing an API endpoint:
- Test the happy path: send a valid request, verify the correct status code and response body.
- Test input validation: send missing fields, wrong types, empty strings — verify 400 responses with helpful error messages.
- Test authentication: send a request without auth — verify 401. Send with invalid auth — verify 401.
- Test authorization: send a request as a user without permission — verify 403.
- Test not found: request a non-existent resource — verify 404.
- Test idempotency: send the same request twice and verify the behavior is correct.
- Test edge cases: very long strings, special characters, large payloads, concurrent requests.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.