Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a default response in Postman mock servers?
A default response is the response that Postman returns when no conditional response matches the request. It acts like a fallback or catch-all answer.
Click to reveal answer
beginner
How do conditional responses work in Postman mock servers?
Conditional responses are set up with rules that check parts of the request, like URL, headers, or body. If the request matches the condition, Postman returns the matching response instead of the default.
Click to reveal answer
intermediate
Why use conditional responses in API testing?
Conditional responses let you simulate different server behaviors based on request details. This helps test how your app handles various scenarios without needing a real server.
Click to reveal answer
intermediate
What happens if no default response is set in a Postman mock server?
If no default response is set and no conditional response matches, the mock server returns a 404 Not Found error because it doesn't know how to respond.
Click to reveal answer
advanced
How can you prioritize multiple conditional responses in Postman?
Postman evaluates conditional responses in the order they are listed. The first matching condition is used, so order your conditions from most specific to least specific.
Click to reveal answer
What does a default response do in a Postman mock server?
AReturns when no conditional response matches
BOverrides all conditional responses
CIs only used for POST requests
DIs the first conditional response checked
✗ Incorrect
The default response acts as a fallback when no conditional response matches the request.
Which request part can you NOT use to create a conditional response in Postman?
ARequest URL
BRequest headers
CRequest body
DResponse status code
✗ Incorrect
Conditional responses are based on request details, not on response status codes.
If multiple conditional responses match a request, which one does Postman use?
AThe last one listed
BThe first one listed
CThe one with the highest status code
DA random one
✗ Incorrect
Postman uses the first matching conditional response it finds in the list.
What status code does Postman return if no response matches and no default is set?
A404 Not Found
B500 Internal Server Error
C200 OK
D400 Bad Request
✗ Incorrect
Without a matching response or default, Postman returns 404 Not Found.
Why are conditional responses useful in API testing?
AThey speed up the server
BThey encrypt the response data
CThey simulate different server behaviors based on requests
DThey automatically fix bugs
✗ Incorrect
Conditional responses let you test how your app handles different server replies by simulating various scenarios.
Explain how default and conditional responses work together in a Postman mock server.
Think about how the server decides which response to send back.
You got /4 concepts.
Describe a real-life situation where using conditional responses in Postman would help your testing.
Imagine testing an app that behaves differently based on user actions.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using default and conditional responses in Postman tests?
easy
A. To send multiple requests at the same time
B. To change the API endpoint dynamically
C. To check different API responses in one test script
D. To automatically generate API documentation
Solution
Step 1: Understand the role of conditional responses
Conditional responses allow testing different API replies based on conditions in one place.
Step 2: Identify the main purpose
This helps verify various outcomes without writing separate tests for each response.
Final Answer:
To check different API responses in one test script -> Option C
Quick Check:
Default and conditional responses = test multiple replies [OK]
Hint: Think: one test script, many response checks [OK]
Common Mistakes:
Confusing response testing with sending requests
Assuming it changes API endpoints
Mixing testing with documentation generation
2. Which of the following is the correct syntax to write a conditional test in Postman to check if the response status is 200?
easy
A. pm.test('Status is 200', () => { if (pm.response.code === 200) { pm.expect(true).to.be.true; } });
B. pm.test('Status is 200', () => { pm.expect(pm.response.code).to.equal(200); });
C. pm.test('Status is 200', () => pm.response.code == 200);
D. pm.test('Status is 200', () => { if (pm.response.status == 200) pm.expect(true); });
Solution
Step 1: Review Postman test syntax
Postman uses pm.test with a callback function and pm.expect for assertions.
Step 2: Identify correct assertion for status code
pm.expect(pm.response.code).to.equal(200) correctly asserts status code equals 200.
Final Answer:
pm.test('Status is 200', () => { pm.expect(pm.response.code).to.equal(200); }); -> Option B
Quick Check:
pm.expect with .to.equal(200) = correct syntax [OK]
Hint: Use pm.expect with .to.equal for exact value checks [OK]
Common Mistakes:
Using '==' instead of .to.equal() in assertions
Checking pm.response.status instead of pm.response.code
Not calling pm.expect properly inside pm.test
3. Given this Postman test code, what will be the test result if the response status is 404?
D. Using assignment '=' instead of comparison '===' in if conditions
Solution
Step 1: Check if condition syntax
The code uses '=' which assigns value instead of '===' for comparison.
Step 2: Understand impact of assignment in conditions
Assignment always returns true, causing logic errors and wrong test behavior.
Final Answer:
Using assignment '=' instead of comparison '===' in if conditions -> Option D
Quick Check:
Use '===' for comparisons, not '=' [OK]
Hint: Use '===' for comparisons, '=' is assignment [OK]
Common Mistakes:
Confusing '=' with '==' or '==='
Ignoring that assignment returns a value
Not validating all possible status codes
5. You want to write a Postman test that checks if the response status is 200 and the JSON body has a 'data' field, but if the status is 404, it should check for an 'error' message. Which code snippet correctly implements this conditional response test?
hard
A. pm.test('Conditional response test', () => {
if (pm.response.code === 200) {
pm.expect(pm.response.json().data).to.exist;
} else if (pm.response.code === 404) {
pm.expect(pm.response.json().error).to.exist;
} else {
pm.expect.fail('Unexpected status code');
}
});
pm.test('Conditional response test', () => {
if (pm.response.code === 200) {
pm.expect(pm.response.json().data).to.exist;
} else if (pm.response.code === 404) {
pm.expect(pm.response.json().error).to.exist;
} else {
pm.expect.fail('Unexpected status code');
}
}); uses '===' for comparisons correctly. Using '=' causes assignment instead of comparison.
Step 2: Verify conditional logic and assertions
The code checks 'data' field existence for status 200, 'error' for 404, and explicitly fails for unexpected codes using pm.expect.fail().
Step 3: Evaluate other options
One option incorrectly combines status and field checks in single pm.expect statements, causing failures. Another does not condition on status codes at all.
Final Answer:
pm.test('Conditional response test', () => {
if (pm.response.code === 200) {
pm.expect(pm.response.json().data).to.exist;
} else if (pm.response.code === 404) {
pm.expect(pm.response.json().error).to.exist;
} else {
pm.expect.fail('Unexpected status code');
}
}); -> Option A
Quick Check:
Use if-else with '===' and proper assertions [OK]
Hint: Use if-else with '===' and separate assertions [OK]