← API Testing with Postman learning pathAPI Testing with Postman · Module 5 of 10
Writing tests in Postman
Add assertions to check responses automatically.
📖 Key ideas
- Tests are JavaScript in the Scripts → Post-response tab.
- pm.test("Status is 200", () => pm.response.to.have.status(200));
- Check JSON: const data = pm.response.json(); pm.expect(data.name).to.eql("Asha");
- Check response time: pm.expect(pm.response.responseTime).to.be.below(500);
- Snippets help write common tests quickly.
💡 Real-life example: Postman tests are a checklist ticked automatically after every delivery arrives.
pm.testDefines a test
pm.expectChai-style assertion
pm.response.json()Parses JSON body
SnippetReady-made test code