Skip to main content

Command Palette

Search for a command to run...

Testing With Postman: Checking Schema

Published
2 min read
Testing With Postman: Checking Schema
B
I build automation frameworks — not just tests. Over 10 years I've designed and shipped production testing platforms across payment, insurance, and healthcare domains. My instinct is always toward architecture: clean abstractions, maintainable patterns, and systems that don't fall apart when the product scales. What I'm working on now: - A Claude/Playwright agent framework that generates test cases directly from Jira tickets - Concurrency and race-condition coverage for financial transactions - A modular Playwright/JavaScript platform covering UI and 20+ API service integrations with 100+ JSON schema validators I've built production automation in Playwright, Geb/Spock, Rest-Assured, and Selenium across payment, insurance, and healthcare domains. When a stack isn't working, I replace it. When a pattern is wrong, I fix it. If the automation problem is interesting, I'm probably already thinking about it.

Schema is something you need to test to make sure when they need a string that it is indeed a string. If you google postman and schema checking you will also find a cool tool called tv4. Do not use this as it is out dated and no longer supported. Please just create a test like below. Also create the jsonData inside the test so it bombs out a single test and not the whole collection when running.

pm.test("Has correct schema", function() {
     let jsonData = pm.response.json()
     pm.expect(jsonData.str).to.be.a("string", "str not a string and instead is " + jsonData.str);
     pm.expect(jsonData.numArray[0]).to.be.a("number", "numArray[0] not a number and instead is " + jsonData.numArray[0]);
     pm.expect(jsonData.numArray[1]).to.be.a("integer", "numArray[1] not a integer and instead is " + jsonData.numArray[1]);
     pm.expect(jsonData.bool).to.be.a("boolean", "bool not a boolean and instead is " + jsonData.bool);
});

You can also output to the console if you would like something added to the log. Below are the different ways you can log to the console.

console.log(); outputs log messages to console console.info(); outputs information messages to console console.warn(); outputs warning messages to console console.error(); outputs error messages to console

An example is if you are calling a string object instead of a string. There is no or in Chai so you will need to use the below code.

pm.expect(jsonData.stringObject).to.be.to.satisfy(function(s){
      return s === null || typeof s == 'string'
}, "stringObject is not a string or null")

Links

Postman Quick Reference Guide Chai Assertion Library Regex Cheat Sheet Postman: The Complete Guide on Udemy