Postman Writing Basic Tests in Postman Estimated reading: 4 minutes 221 views Writing Basic Tests in Postman is one of the easiest and most effective ways to start validating your API responses automatically. Whether you’re new to API testing or already running manual tests, adding simple Postman tests can transform how you work. We’ll walk through the process together, using Postman’s built-in JavaScript testing framework to create reliable, dynamic checks that can scale with your projects.In this guide, we’ll keep things simple and practical. You don’t need to be a JavaScript expert or have a complex setup just a working API and the curiosity to automate. Let’s dive in and make testing a breeze.Why Writing Basic Tests in Postman MattersAs QA testers, we often rely on Postman to send requests and inspect responses. But the real value comes when we stop clicking and start scripting.When you write basic tests in Postman, you can: Automatically check if your API responses return the correct status codes. Validate that required data fields exist and are in the right format. Catch broken or unexpected responses early before they hit production. Improve team confidence and reduce bugs across releases.You’re not just verifying outputs you’re building trust in your system.Writing Basic Tests in PostmanLet’s begin with the essentials. After sending any API request in Postman, you’ll see a Tests tab. This is where you’ll write test scripts using JavaScript and the Postman Sandbox API.Let’s imagine you’re testing a Billing API, and you’ve just sent a GET /api/billing/:id request. The response includes fields like personId, amount, and subscriptionName. Your job is to confirm that those fields exist, are valid, and return expected formats without hardcoding anything.GET: Billing Details By ID{ "personId": "680d5cd6a302cb5bad00dd24", "streetAddress": "1420 Elmo St", "city": "Austin", "state": "TX", "zip": "73301", "phoneNumber": "(512) 555-1234", "cardNumber": "4111 1111 1111 1111", "expDate": "12/26", "cvv": "123", "subscriptionName": "Premium", "amount": 49.99, "createdAt": "2025-04-26T22:23:18.949Z", "updatedAt": "2025-04-27T07:16:04.679Z", "id": "680d5cd6a302cb5bad00dd39" }Instead of validating these fields manually, you can add dynamic scripts to check them every time the test runs.Status Code TestChecking the HTTP status code is one of the most basic but essential tests. Here’s how you can ensure your request was successful:JavaScriptpm.test("Status code is 200", function () { pm.response.to.have.status(200); }); Postman Status Code TestThis test will pass if the response status is 200 and fail otherwise. It’s your first line of defense.Content-Type HeaderWe want to confirm that the response is in JSON format:JavaScriptpm.test("Content-Type is application/json", function () { pm.response.to.have.header("Content-Type", "application/json; charset=utf-8"); }); Postman Content Type TestDynamic Field Checks in JSONHere’s how we check if the billing record contains the necessary data:JavaScriptlet jsonData = pm.response.json(); pm.test("personId is a string", function () { pm.expect(jsonData.personId).to.be.a("string"); }); pm.test("amount is a number above 0", function () { pm.expect(jsonData.amount).to.be.a("number"); pm.expect(jsonData.amount).to.be.above(0); }); pm.test("subscriptionName exists and is not empty", function () { pm.expect(jsonData.subscriptionName).to.be.a("string").and.not.empty; }); Postman Dynamic Fields TestsWith these tests, you’re no longer just looking at the response you’re confirming it’s structured correctly, dynamic values and all.Address and Timestamp ChecksLet’s validate address-related fields and confirm date formats:JavaScriptlet jsonData = pm.response.json(); pm.test("Address fields are valid", function () { pm.expect(jsonData.streetAddress).to.be.a("string").and.not.empty; pm.expect(jsonData.city).to.be.a("string"); pm.expect(jsonData.state).to.be.a("string"); pm.expect(jsonData.zip).to.match(/^\d{5}$/); // basic US ZIP check }); pm.test("Timestamps are valid ISO strings", function () { pm.expect(Date.parse(jsonData.createdAt)).to.be.a("number"); pm.expect(Date.parse(jsonData.updatedAt)).to.be.a("number"); }); Postman Address & Timestamps TestThese tests are especially helpful when you’re dealing with billing history or audit trails where accuracy matters.Viewing Test ResultsOnce you’ve written your test scripts and hit Send , it’s time to see how your API performs. Postman makes this incredibly intuitive with its built-in Test Results tab This result PASSEDmeans your test ran successfully. This result FAILEDmeans something didn’t meet your expectations.Understanding Failed Test AssertionsPostman’s test failures show exactly what went wrong, making it easier to debug quickly. Let’s look at two examples from your tests. Postman Failed Tests ❌ Address fields are valid Error:expected '1420 Elmo St' to be a numberCaused by: pm.expect(jsonData.streetAddress).to.be.a("number")but streetAddress is a string.Fix: Change "number" to "string". ❌ Timestamps are valid ISO strings Error:expected 1745706198949 to be a stringCaused by: Tested Date.parse(jsonData.createdAt) as a string, but it returns a number.Fix: Change "string" to "number".ConclusionWriting Basic Tests in Postman is a great first step toward automating and validating your APIs. With just a few lines of JavaScript, you can check status codes, headers, and dynamic data no complex setup required. As your API grows, these tests can scale into full collections, CI/CD integrations, and multi-environment setups. Now that you’ve mastered the basics, let’s move on to Using Variables for Dynamic Testing.Tagged:Postman Postman - Previous Organizing Tests with Collections and Variables Next - Postman Using Variables for Dynamic Testing in Postman