Skip to content
CheckcraftDownload
Practical workflow

Postman tests: checking responses with pm.test, examples and running a collection

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

A Postman test is a script that runs after the response and checks it. Tests go on the Scripts tab, Post-response section, in JavaScript with the pm object. The most common mistake is checking only status 200: such a test stays green when the data is wrong. Below are checks that catch real bugs.

Checkcraft ·

Get help with your first test →

Where to write tests

Open the request, the Scripts tab and the Post-response section. In older Postman versions this tab was called Tests. Snippets on the right insert templates such as a status check, but you must add your own fields and expectations.

What to check besides status

Required fields, their types, allowed status values, calculations such as a discounted total, field relations and the absence of extra data like password hashes. A good trick: break the expected value and make sure the test goes red. If it does not, it checks nothing.

Postman diagram: workspace, collection, folder, request, tabs

Running in bulk

The Collection Runner runs all requests of a collection in order and shows failing tests. For CI use the Postman CLI or Newman. Note that the Postman free plan is now for a single user.

Ready response tests

pm.test("статус 201", () => pm.response.to.have.status(201));

const order = pm.response.json();

pm.test("есть номер заказа", () => {
  pm.expect(order.id).to.be.a("number");
});

pm.test("итог = сумма позиций минус скидка", () => {
  const subtotal = order.items.reduce((s, i) => s + i.qty * i.price, 0);
  pm.expect(order.total).to.eql(subtotal - order.discount);
});

pm.test("статус из допустимого списка", () => {
  pm.expect(["NEW", "PAID", "SHIPPED", "CANCELLED"]).to.include(order.status);
});

pm.test("нет лишних полей с секретами", () => {
  pm.expect(order).to.not.have.property("passwordHash");
});

pm.test("ответ быстрее 800 мс", () => pm.expect(pm.response.responseTime).to.be.below(800));

// сохранить id для следующего запроса цепочки
pm.collectionVariables.set("orderId", order.id);

Each pm.test is reported separately, so a failure shows exactly what broke. The last line saves the order id for the next chained request: request chains.

Postman request steps: method and URL, headers and body, Send, response, test

Weak vs strong checks

Weak checkWhat it missesStrong check
status 200Wrong datastatus + fields + calculations
total existsWrong amounttotal = items sum − discount
status not emptyTypo PAYEDstatus from the documented list
response not emptyLeaked passwordHashno fields outside the contract

If an AI wrote the tests, review them: they often only check that a response arrived. See empty AI tests.

More on Postman

Section overview and all guides: Postman requests: how to send GET, POST, PUT and DELETE with examples.

Frequently asked questions

Where do Postman tests go?

Scripts → Post-response (formerly the Tests tab).

How do I check a JSON field?

pm.response.json() and pm.expect inside pm.test.

How do I run all tests?

Collection Runner, Postman CLI or Newman.

Next step

Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

Download FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

Postman: test scripts

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.