Verify API response using Postman mock server URL
Preconditions (2)
✅ Expected Result: The response status code is 200 and the response body matches the predefined mock user data
Jump into concepts and practice - no test required
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response body has expected user data', () => { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('id'); pm.expect(jsonData).to.have.property('name', 'John Doe'); pm.expect(jsonData).to.have.property('email', 'john.doe@example.com'); });
The first test checks if the response status code is 200, which means the request was successful.
The second test parses the JSON response body and verifies that it contains the expected user data properties: id, name with value 'John Doe', and email with value 'john.doe@example.com'.
Using pm.response.to.have.status and pm.expect ensures clear and readable assertions. This script runs automatically after the request is sent to the mock server URL.
Now add data-driven testing with 3 different mock user responses
mock server URL in Postman?https://mockserver.com/12345/api/users, what will happen if you send a GET request to this URL in Postman?https://mockserver.com/api/users. What issue will you face?/products using a Postman mock server. Your mock server URL is https://mockserver.com/abcde. Which is the correct full URL to use in your request to get the mocked /products response?/products directly after the unique ID in the URL.