Writing API Assertions: Testing Responses with pm.test and pm.expect

An assertion is a script-level check that turns “I looked at the response and it seemed fine” into something automated and repeatable: a specific claim about the response that either holds or doesn’t, run the same way every single time the request executes.

Writing a Test

Assertions live inside a post-response script, wrapped in pm.test():

pm.test('Status is 200', () => {
  pm.expect(pm.response.status).to.equal(200);
});

pm.test('Response has a user id', () => {
  pm.expect(pm.response.json()).to.have.property('id');
});

Each pm.test() call is independent — one throwing an assertion error fails that test without stopping the others from running, so a single response can carry several unrelated checks in one script.

Available Matchers

pm.expect() supports a focused set of chainable matchers, not the full surface of a general-purpose assertion library:

  • .to.equal(value) — strict equality
  • .to.a(type) — type check ('string', 'number', 'array', etc.)
  • .to.include(value) — substring match on a string, or membership check on an array
  • .to.have.property(key) — object has the given key
  • .to.be.above(n) / .to.be.below(n) — numeric comparison
  • .to.have.status(code) — status code match
  • Prefixing with .not negates any of the above

There’s no .deep.equal, .match() (regex), or .length matcher — for anything those would normally cover, a plain JavaScript expression inside pm.test() works just as well.

Response Shortcuts

A couple of common checks skip pm.expect() entirely:

pm.test('Status is 200', () => {
  pm.response.to.have.status(200);
});

pm.test('Response is JSON', () => {
  pm.response.to.be.json;
});

Seeing Results

After a request runs, its test results show up in a dedicated panel: a summary line (“3 / 4 tests passed”) followed by each test’s name, a pass/fail indicator, how long it took, and — for anything that failed — the actual error so you’re not left guessing which assertion broke or why.

Testing Assertions in HTTP Titan

Write pm.test() blocks in a request’s post-response script, using pm.expect() or the pm.response.to.* shortcuts to check status codes, REST response bodies, and headers. Every run reports a clear pass/fail breakdown per test, so a request you’ve already verified once stays verified on every future send — a regression is a red line in the results panel, not something you have to notice by eye.