Create and verify a mock response for a GET user API
Preconditions (2)
✅ Expected Result: The mock server returns the defined JSON response with status 200 when GET /user is called
Jump into concepts and practice - no test required
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response body matches mock data', () => { const jsonData = pm.response.json(); pm.expect(jsonData).to.eql({ id: 1, name: 'John Doe' }); });
The first test checks that the response status code is exactly 200, which means success.
The second test parses the response body as JSON and compares it to the expected mock object with id 1 and name 'John Doe'.
Using pm.test groups assertions with clear names, making test reports easy to understand.
This script runs automatically after sending the request to the mock server, verifying the mock response is correct.
Now add data-driven testing by defining three different mock responses for GET /user with different user data and verify each response.