But the test fails with a KeyError. What is the likely cause?
medium
A. The response status code is not 200.
B. The API response JSON does not include the 'name' field as per contract.
C. The test used the wrong HTTP method.
D. The client.get() method is not defined.
Solution
Step 1: Understand the test failure
A KeyError means the 'name' key is missing in the JSON response.
Step 2: Identify contract violation
The API response does not include the expected 'name' field, violating the contract.
Final Answer:
The API response JSON does not include the 'name' field as per contract. -> Option B
Quick Check:
Missing 'name' key causes KeyError [OK]
Hint: KeyError means expected JSON key missing in response [OK]
Common Mistakes:
Assuming wrong HTTP method caused error
Ignoring status code correctness
Blaming client.get() method existence
5. You have a REST API contract that requires the endpoint /orders/{id} to return a JSON with fields id, status, and items (a list). Which test best validates this contract?
hard
A. Send GET /orders/10, check status 200, verify JSON has 'id', 'status', and 'items' keys, and 'items' is a list.
B. Send POST /orders with empty body and expect status 201.
C. Send GET /orders/10 and check only the status code is 404.
D. Send DELETE /orders/10 and expect status 500.
Solution
Step 1: Identify contract requirements
The contract requires GET /orders/{id} to return JSON with 'id', 'status', and 'items' keys, where 'items' is a list.
Step 2: Match test to contract validation
Sending GET /orders/10, checking status 200, verifying JSON has 'id', 'status', and 'items' keys, and confirming 'items' is a list fully validates the contract.
Final Answer:
Send GET /orders/10, check status 200, verify JSON has 'id', 'status', and 'items' keys, and 'items' is a list. -> Option A
Quick Check:
Test checks all required fields and types [OK]
Hint: Check all required fields and data types in JSON response [OK]
Common Mistakes:
Testing wrong HTTP method
Ignoring required JSON fields
Not verifying data types like list
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.