In API testing using Postman, why do we validate the response body and status code?
Think about what confirms the API behaves as expected.
Validating the response body and status code confirms the API returns the correct data and signals success or failure properly. This ensures the API works as intended.
Given this Postman test script, what will be the test result?
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response has userId 5', () => { const jsonData = pm.response.json(); pm.expect(jsonData.userId).to.eql(5); });
Check what conditions the tests verify.
The script checks two things: the HTTP status code must be 200, and the JSON response must have a userId equal to 5. Both must be true to pass.
You want to check that the JSON response has a field status with value success. Which assertion is correct?
Remember to access JSON data properly and use the right assertion method.
Option D correctly accesses the JSON response and checks if the status field equals the string 'success'. Other options either access wrong properties or use incorrect assertion methods.
Consider this Postman test script:
pm.test('Check user name', () => {
const data = pm.response.json();
pm.expect(data.username).to.eql('john_doe');
});The test fails even though the response JSON has a userName field with value 'john_doe'. Why?
Check the exact spelling and case of JSON keys.
JSON keys are case-sensitive. The test looks for 'username' but the response has 'userName'. This mismatch causes the test to fail.
In a continuous integration/continuous deployment (CI/CD) pipeline, why is automating response validation in Postman tests critical?
Think about the role of automated tests in software delivery.
Automated response validation in CI/CD pipelines helps catch API errors early by running tests on every code change. This prevents faulty code from reaching production.