Why is testing APIs important in software development?
Think about what APIs do between different software parts.
APIs allow different software parts to communicate. Testing ensures data is exchanged correctly and the system works as expected.
What is the output status code when this Postman test script runs if the API returns success?
pm.test('Status code is 200', function () { pm.response.to.have.status(200); });
Look at the status code the test expects.
The test checks if the response status code is 200. If yes, the test passes.
Which Postman test assertion correctly checks that the JSON response has a key named 'userId'?
Check the correct syntax for property assertion in Postman.
Option A uses the correct Postman syntax to assert that the JSON response contains the 'userId' property.
What error will this Postman test script cause?
pm.test('Check user name', function() { let jsonData = pm.response.json(); pm.expect(jsonData.name).to.eql('Alice'); });
Check how to correctly call the json method in Postman.
pm.response.json is a function (method) and must be called with parentheses: pm.response.json(). Without them, jsonData is the function reference itself, not the parsed JSON object. Thus, jsonData.name is 'json' (the function name), causing the test to fail.
Which approach is best for automating API tests to ensure reliability and maintainability?
Think about how to keep tests organized and easy to update.
Using a testing framework with reusable tests and environment variables helps keep API tests reliable, maintainable, and easy to run in different setups.