Recall & Review
beginner
What is the purpose of the Tests tab in Postman?
The Tests tab in Postman is used to write scripts that run after a request is sent. These scripts check if the response meets expected conditions, helping verify the API works correctly.
Click to reveal answer
beginner
What does the pm.test() function do in Postman?
The pm.test() function defines a test with a name and a function containing assertions. It runs the test and reports if it passed or failed based on the assertions inside.
Click to reveal answer
beginner
Write a simple pm.test() example that checks if the response status code is 200.
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
Click to reveal answer
beginner
Why is it important to name your tests clearly in pm.test()?
Clear test names help you understand what each test checks when you see the test results. It makes debugging easier if a test fails.
Click to reveal answer
intermediate
How can you check if a JSON response contains a specific key using pm.test()?
Use pm.test() with pm.response.json() to parse the response and then check the key. Example:
pm.test("Response has userId", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('userId');
});Click to reveal answer
What does pm.test() require as arguments?
✗ Incorrect
pm.test() needs a descriptive test name and a function that contains the assertions to check the response.
Where do you write pm.test() scripts in Postman?
✗ Incorrect
The Tests tab is where you write scripts that run after the request completes.
Which assertion checks if the response status code is 200?
✗ Incorrect
The correct syntax to assert status code 200 is pm.response.to.have.status(200);
What happens if an assertion inside pm.test() fails?
✗ Incorrect
If an assertion fails, the test is marked as failed and shown in the test results.
How do you access the JSON response body inside pm.test()?
✗ Incorrect
pm.response.json() parses the response body as JSON for assertions.
Explain how to write a test in Postman using pm.test() to check if the response status code is 200.
Think about naming the test and the assertion syntax.
You got /3 concepts.
Describe the role of the Tests tab in Postman and how pm.test() fits into it.
Consider when tests run and what they do.
You got /4 concepts.