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 reportPrepare 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,400Save 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
- Click the collection name and choose Run.
- Select the requests you want to include.
- Click Select File beside Data and choose your CSV or JSON file.
- Check the preview. Postman shows how many iterations the file creates.
- Click Run.
The results screen groups outcomes by iteration. Expand any iteration to inspect its requests, inputs, and test results.
Designing Good Test Data
| Category | Example Inputs |
|---|---|
| Valid | Typical names and emails |
| Invalid format | An email without the @ symbol |
| Empty | Blank name or missing field |
| Boundary | One-character and maximum-length names |
| Special characters | Apostrophes, accents, and symbols |
| Duplicates | An 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.jsonTips 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.
