End-to-end contract testing
A serverless REST path includes the public method and route, authorization, integration mapping, handler, and persistence. Unit tests isolate code; integration tests exercise boundaries between services. Define requests and observable responses before building, and include malformed input, missing authorization, duplicate requests, and dependency failures in the acceptance contract. For example, pOST /orders with valid JSON returns a created order ID; the same idempotency key returns the existing order rather than a second record.
POST /orders with valid JSON returns a created order ID; the same idempotency key returns the existing order rather than a second record.
Begin with a client contract: POST /registrations receives JSON, requires a valid credential, and returns either a registration identifier or a documented error. A handler unit test can prove input validation, but it does not prove the gateway forwards the body correctly or applies the intended authorizer. An integration test sends the request through the deployed endpoint and observes both the HTTP result and durable outcome.
A unit test isolates a small component. An integration test checks communicating components. A contract describes observable request and response behavior. Separate test failures by layer: an unauthorized request should fail before creating data; malformed input should produce the chosen client error; a valid authorized request should create exactly the intended record. Deployment-stage configuration and payload versions can differ from local assumptions. Integration tests offer stronger boundary evidence but require controlled setup, scoped data, credentials, and cleanup. They should not use production customer records merely because the endpoint already exists.
Boundary tests catch mismatches between individually correct components, including event shapes and response formats that local handler unit tests cannot reveal by themselves.
Calling only the function directly and declaring the public API tested skips authorizers, deployment stages, gateway mapping, and client-visible error status behavior.