0
0
Testing Fundamentalstesting~20 mins

Request and response validation in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Request & Response Validation 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 API response validation code?

Consider this Python code snippet that validates an API JSON response status and content:

response = {'status_code': 200, 'data': {'user': 'alice', 'id': 123}}

assert response['status_code'] == 200
assert 'user' in response['data']
print('Validation passed')

What will be printed when this code runs?

Testing Fundamentals
response = {'status_code': 200, 'data': {'user': 'alice', 'id': 123}}

assert response['status_code'] == 200
assert 'user' in response['data']
print('Validation passed')
AKeyError
BAssertionError
CTypeError
DValidation passed
Attempts:
2 left
💡 Hint

Check if the status code is 200 and if the key 'user' exists in the nested data dictionary.

assertion
intermediate
2:00remaining
Which assertion correctly checks the response contains a non-empty 'items' list?

You receive this JSON response from an API:

{'status': 'success', 'items': [1, 2, 3]}

Which assertion statement correctly verifies that 'items' exists and is not empty?

Aassert response['items'] != None
Bassert 'items' in response and len(response['items']) > 0
Cassert response['items'] is not []
Dassert response['items']
Attempts:
2 left
💡 Hint

Check both the presence of the key and that the list has elements.

🔧 Debug
advanced
2:00remaining
Why does this request validation test fail with a KeyError?

Given this test code snippet:

request = {'method': 'POST', 'body': {'username': 'bob'}}
assert request['body']['password'] == 'secret'

Why does this test raise a KeyError?

Testing Fundamentals
request = {'method': 'POST', 'body': {'username': 'bob'}}
assert request['body']['password'] == 'secret'
AThe 'password' key does not exist in the 'body' dictionary, causing KeyError
BThe 'body' key is missing in the request dictionary
CThe 'method' key is not 'POST', causing assertion failure
DThe 'password' value is None, causing TypeError
Attempts:
2 left
💡 Hint

Check if the key you access exists in the dictionary.

🧠 Conceptual
advanced
2:00remaining
What is the main purpose of response schema validation in API testing?

Why do testers perform response schema validation when testing APIs?

ATo ensure the response structure and data types match the expected format
BTo check if the API server is running and reachable
CTo verify the response time is under a threshold
DTo confirm the API request headers are correctly set
Attempts:
2 left
💡 Hint

Think about what schema means in data context.

framework
expert
2:00remaining
Which test framework feature best supports automated request and response validation?

In automated API testing, which feature of a test framework helps validate both request payloads and response data effectively?

AStatic code analysis tools for syntax checking
BManual test case execution with screenshots
CData-driven testing with parameterized test cases
DVersion control integration for code commits
Attempts:
2 left
💡 Hint

Consider how to run the same test with many input and output variations automatically.