0
0
Rest APIprogramming~20 mins

Integration testing in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Integration Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this integration test response check?

Consider a REST API integration test that sends a GET request to /users/123. The test expects a JSON response with the user's name and status code 200.

What will be the printed output of this test snippet?

Rest API
response = client.get('/users/123')
if response.status_code == 200 and response.json().get('name') == 'Alice':
    print('Test Passed')
else:
    print('Test Failed')
ATest Failed
BTest Passed
CKeyError
DAttributeError
Attempts:
2 left
💡 Hint

Check if the response status and JSON content match the expected values.

🧠 Conceptual
intermediate
1:30remaining
Which component is typically NOT tested in integration testing of REST APIs?

Integration testing usually checks how different parts of a system work together. Which of these is least likely to be tested during REST API integration testing?

AIndividual function logic inside a utility module
BAPI endpoint response format correctness
CDatabase interaction with API endpoints
DAuthentication flow between client and server
Attempts:
2 left
💡 Hint

Think about what integration testing focuses on versus unit testing.

🔧 Debug
advanced
2:00remaining
Why does this integration test fail with a timeout error?

Given this integration test code snippet that calls an external API endpoint, why does it fail with a timeout error?

Rest API
response = client.get('/external-data', timeout=0.001)
print(response.status_code)
AThe timeout value is too low causing the request to abort before response
BThe endpoint URL is incorrect causing no response
CThe client.get method does not support timeout parameter
DThe response object does not have a status_code attribute
Attempts:
2 left
💡 Hint

Consider what happens if the timeout is set very low.

📝 Syntax
advanced
2:30remaining
Which option correctly mocks an API response in integration testing?

You want to mock a REST API response in your integration test using Python's unittest.mock. Which code snippet correctly mocks the client.get method to return a response with status code 200 and JSON {'success': true}?

A
with patch('client.get') as mock_get:
    mock_get.return_value = {'status_code': 200, 'json': {'success': True}}
B
with patch('client.get') as mock_get:
    mock_get.status_code = 200
    mock_get.json = {'success': True}
C
with patch('client.get') as mock_get:
    mock_get.return_value.status_code = 200
    mock_get.return_value.json = lambda: {'success': True}
D
with patch('client.get') as mock_get:
    mock_get.return_value.status_code = 200
    mock_get.return_value.json = {'success': True}
Attempts:
2 left
💡 Hint

Remember that json is a method, not a property.

🚀 Application
expert
2:00remaining
What is the number of items in the combined response after integration test aggregation?

An integration test calls two API endpoints: /products returning 3 items and /categories returning 2 items. The test aggregates both JSON lists into one list.

How many items will the combined list contain?

Rest API
products = client.get('/products').json()  # returns list of 3 items
categories = client.get('/categories').json()  # returns list of 2 items
combined = products + categories
print(len(combined))
A2
B6
C3
D5
Attempts:
2 left
💡 Hint

Think about how list concatenation works in Python.