QA Automation Engineer interview question
What is API contract testing?
Contract tests verify that provider requests and responses satisfy schemas and consumer expectations independently of full end-to-end flows. They catch incompatible field, type, status and semantic changes before deployment.
Direct answer
What a strong answer covers
How it works
A contract test checks that a provider’s API and a consumer’s expectations of it agree, without deploying both and running a full journey. Consumer-driven contracts record what each consumer actually sends and needs back, as a pact file; the provider runs those interactions against itself in CI and fails if a field, type, status code, or meaning it depends on changed. Schema-based contract tests validate requests and responses against an OpenAPI definition on both sides. Either way, breaking changes are caught at build time of the party that made them, and the end-to-end suite can shrink to the journeys that need real integration.
Example
The mobile app publishes a pact stating that GET /orders/{id} returns status, total as a number, and items with a sku. When the orders team changed total to a string with currency formatting, their provider verification build failed with the mobile app’s expectation named, before the change reached any environment. The same mechanism let the web team confirm that a new optional field would not break the three existing consumers.
Common mistakes
- Writing contract tests that only check the schema and miss a change in a field’s meaning.
- Maintaining a mock server by hand and letting it drift from the real provider.
- Replacing every integration test with contract tests and never exercising the real network path.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.