Bird
0
0

What will be the result of this test code?

medium📝 Predict Output Q5 of 15
Rest API - API Testing and Monitoring
What will be the result of this test code?
response = client.post('/login', json={'user':'bob'})
assert response.status_code == 201
assert response.json()['token'] != ''
ATest passes if token is empty string
BTest fails if status code is 200
CTest passes if login creates a token and returns status 201
DTest fails if response has no JSON
Step-by-Step Solution
Solution:
  1. Step 1: Understand status code assertion

    The test expects status 201, meaning resource created (token).
  2. Step 2: Understand token assertion

    The test checks token field is not empty, confirming token creation.
  3. Final Answer:

    Test passes if login creates a token and returns status 201 -> Option C
  4. Quick Check:

    Status 201 + non-empty token = Test passes if login creates a token and returns status 201 [OK]
Quick Trick: Check status and token presence for login success [OK]
Common Mistakes:
MISTAKES
  • Assuming status 200 is correct for creation
  • Allowing empty token as success
  • Ignoring JSON response presence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes