Verify POST request with JSON body to create a new user
Preconditions (3)
✅ Expected Result: Response status code is 201 Created and response body contains the created user details with name 'John Doe', email 'john.doe@example.com', and age 30
pm.test('Status code is 201', function () { pm.response.to.have.status(201); }); pm.test('Response has correct user details', function () { const jsonData = pm.response.json(); pm.expect(jsonData.name).to.eql('John Doe'); pm.expect(jsonData.email).to.eql('john.doe@example.com'); pm.expect(jsonData.age).to.eql(30); });
The first test checks that the response status code is 201, which means the user was created successfully.
The second test parses the JSON response body and verifies that the 'name', 'email', and 'age' fields match the expected values sent in the request.
This ensures the API correctly processed the JSON body and returned the expected data.
Now add data-driven testing with 3 different user JSON bodies to create multiple users
{"name": "Alice", "age": 30} uses double quotes correctly around keys and string values. The other options use incorrect quotes or syntax.{"colors": ["red", "green", "blue"]} correctly uses square brackets and double quotes. The other options are invalid: one uses parentheses, another is missing array brackets, and one lacks quotes around strings and keys.{
"user": {
"id": 101,
"active": true
},
"roles": ["admin", "editor"]
}user.active?{
"product": "Book",
"price": 12.99,
"inStock": yes
}{
"user": {
"name": "Bob",
"email": "bob@example.com",
"preferences": {
"notifications": false,
"themes": ["dark", "blue"]
}
}
}{ "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"], "language": "en" } } } adds "language": "en" inside "preferences" correctly. { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "language": "en" } } adds "language" outside "preferences". { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "preferences.language": "en" } } uses invalid key "preferences.language". { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "preferences": { "language": "en" } } } overwrites "preferences" object, losing existing keys.Pass the test and this pattern moves unknown