Writing Tests with Postman Scripts & Assertions
Where Tests Live
Tests are written in the Tests tab of a request and run automatically after the response is received. Postman also provides a snippets panel with ready-made test templates.
Basic Assertion Structure
A test is wrapped in pm.test("description", function () { ... }), with assertions inside using pm.expect() to check values against expected results.
Common Assertions
| Assertion | Checks |
|---|---|
| Status code | Response returned the expected status |
| Response time | Request completed within a limit |
| Header presence | Expected header exists |
| Body content | Response contains expected values |
Viewing Test Results
After sending a request, the Test Results tab shows a pass/fail summary for every assertion, making it easy to spot failures at a glance.
Basic assertions are a great start - next, let's dig into custom tests for more detailed response validation.
Ready to master Postman API Testing Course?
Join Uncodemy's hands-on training and build real-world API testing skills with expert mentors.