Verify GET request to fetch user details
Preconditions (2)
✅ Expected Result: Response status code is 200 and response body contains user details with id 123
pm.test('Status code is 200', function () { pm.response.to.have.status(200); }); pm.test('Response has user id 123', function () { const jsonData = pm.response.json(); pm.expect(jsonData.id).to.eql(123); }); pm.test('Response has required keys', function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.all.keys('id', 'name', 'email'); });
The first test checks if the response status code is 200, which means the request was successful.
The second test parses the JSON response and verifies the user id is exactly 123.
The third test ensures the response JSON contains the keys 'id', 'name', and 'email', confirming the expected data structure.
All tests use Postman's pm and pm.expect APIs for clear and reliable assertions.
Now add tests for POST request to create a new user with 3 different user data inputs
{
"name": "Alice",
"age": 30
}{
"id": 101,
"name": "Alice",
"age": 30
}Pass the test and this pattern moves unknown