Bird
0
0

Given this test code snippet for a REST API endpoint:

medium📝 Predict Output Q13 of 15
Rest API - API Testing and Monitoring
Given this test code snippet for a REST API endpoint:
response = client.get('/users/123')
assert response.status_code == 200
assert 'id' in response.json()
assert response.json()['id'] == 123

What does this test validate about the API contract?
AThe API returns status 200 and correct user id in JSON response.
BThe API returns status 404 for missing users.
CThe API accepts POST requests at /users/123.
DThe API returns an empty JSON response.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the test assertions

    The test checks that the response status code is 200 and the JSON response contains an 'id' key equal to 123.
  2. Step 2: Understand what this means for the API contract

    This confirms the API returns successful status and correct user data as per contract.
  3. Final Answer:

    The API returns status 200 and correct user id in JSON response. -> Option A
  4. Quick Check:

    Test checks status 200 and user id = 123 [OK]
Quick Trick: Check status and key-value in JSON to validate contract [OK]
Common Mistakes:
MISTAKES
  • Confusing status 404 with 200
  • Assuming POST method is tested here
  • Ignoring JSON content checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes