0
0
Postmantesting~5 mins

Tests tab and pm.test() in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AOnly a function with assertions
BOnly a test name
CA test name and a function with assertions
DA request URL and headers
Where do you write pm.test() scripts in Postman?
AIn the Tests tab after sending a request
BIn the Body tab before sending a request
CIn the Headers tab
DIn the Authorization tab
Which assertion checks if the response status code is 200?
Apm.response.to.have.status(200);
Bpm.response.status(200);
Cpm.response.code(200);
Dpm.response.check(200);
What happens if an assertion inside pm.test() fails?
AThe test passes anyway
BThe request is resent automatically
CPostman stops running all tests
DThe test fails and is reported in the test results
How do you access the JSON response body inside pm.test()?
AUsing pm.response.text()
BUsing pm.response.json()
CUsing pm.response.body()
DUsing pm.request.json()
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.