API and Contract Testing Questions

Testing services and their interfaces directly. Covers REST and other API testing, request/response and schema validation, status and error handling, and contract testing between producers and consumers. Includes service-level and integration testing without a UI.

EasyTechnical
68 practiced

What does a solid test-data strategy for API and service tests actually look like in practice? Cover how you'd decide between generating data on the fly versus using fixed fixtures, when synthetic data is good enough versus when you need something closer to real production data, and how you keep tests from interfering with each other's data.

EasyTechnical
53 practiced

You're asserting that an API uses HTTP status codes correctly across the full 1xx-5xx range. How would you organize those assertions by range, and what's a realistic way a service could return the wrong status code while still looking superficially correct? Write a test that would catch that specific case. How should an automated test treat an asynchronous 202 response differently from an immediate 200 or 201?

MediumTechnical
62 practiced

Write a parameterized test that checks an API's input validation by sending it several different invalid payloads and confirming each one produces the expected status code and error message. How would you structure the test data so the suite stays maintainable as more invalid cases are added?

MediumTechnical
74 practiced

You consume webhooks from an external vendor that signs each payload with HMAC SHA-256 and includes a timestamp to guard against replay. Write a Postman pre-request script (or describe the equivalent code) that generates the correct signature header for a test webhook request, and describe the automated tests you'd write on the receiver side to verify signature validation, timestamp freshness, and replay protection.

MediumTechnical
74 practiced

Walk through how a consumer-driven contract testing tool like Pact actually operates end to end: how the consumer test generates a contract, how that contract gets published and versioned, and how the provider verifies against it in its own CI. Where does this approach break down, and how would you introduce it to a team that has never used it before?

Unlock Full Question Bank

Get access to all 29 API and Contract Testing interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.