Postman Data Driven Testing

A single request often needs checking with many different inputs: valid emails, invalid emails, empty values, and extreme sizes. Typing each case by hand takes hours. Data driven testing feeds a file of inputs into the Collection Runner, and Postman repeats the whole collection once per row.

The Idea in Layman's Terms

Picture a factory quality inspector who tests a lamp. Instead of building a new inspection process for each lamp, the inspector follows one checklist and applies it to every lamp on the conveyor belt. The collection is the checklist. The data file is the conveyor belt.

  DATA FILE                     COLLECTION
  ─────────                     ──────────
  Row 1: ana@mail.com   ───►    Run all requests with row 1
  Row 2: bad-email      ───►    Run all requests with row 2
  Row 3: (empty)        ───►    Run all requests with row 3

  Result: 3 iterations, each with its own pass or fail report

Prepare a CSV File

The first row holds the variable names. Each following row holds one test case.

name,email,expectedStatus
Asha,asha@example.com,201
Ravi,ravi@example.com,201
Maya,not-an-email,400
,empty@example.com,400

Save the file as users.csv. Avoid spaces in column names because they become variable names.

Prepare a JSON File

JSON files suit nested data and mixed types.

[
  { "name": "Asha", "email": "asha@example.com", "expectedStatus": 201 },
  { "name": "Maya", "email": "not-an-email",    "expectedStatus": 400 }
]

Use Data Values in a Request

Reference each column with curly braces, exactly like a variable.

POST {{baseUrl}}/users

Body (raw JSON):
{
  "name": "{{name}}",
  "email": "{{email}}"
}

Check Results with Data Values

Scripts read the current row through the iterationData object.

const expected = Number(pm.iterationData.get("expectedStatus"));

pm.test("Status matches expected value", function () {
    pm.expect(pm.response.code).to.equal(expected);
});

Each iteration compares the real status with the number from its own row, so valid and invalid cases share one test.

Run the Data File

  1. Click the collection name and choose Run.
  2. Select the requests you want to include.
  3. Click Select File beside Data and choose your CSV or JSON file.
  4. Check the preview. Postman shows how many iterations the file creates.
  5. Click Run.

The results screen groups outcomes by iteration. Expand any iteration to inspect its requests, inputs, and test results.

Designing Good Test Data

CategoryExample Inputs
ValidTypical names and emails
Invalid formatAn email without the @ symbol
EmptyBlank name or missing field
BoundaryOne-character and maximum-length names
Special charactersApostrophes, accents, and symbols
DuplicatesAn email that already exists

Data Scope Priority

Data values sit above environment and collection variables in priority. A column named baseUrl in the data file overrides the environment value for that iteration. Choose column names carefully to avoid accidental overrides.

Run from the Command Line

Newman accepts the same files, which allows data driven runs inside automated pipelines.

newman run shop-collection.json -d users.csv -e staging.json

Tips for Maintainable Data Files

  • Keep one file per scenario, such as valid-users.csv and invalid-users.csv.
  • Store an expected result column beside each input.
  • Use fake data only. Never place real customer details in test files.
  • Version the data files together with the collection.

Key Points

  • A data file turns one collection into many test cases.
  • CSV suits flat data and JSON suits nested data.
  • Column names become variables inside requests.
  • The iterationData object lets tests read expected values per row.
  • Newman supports the same data files for automated runs.