← Back to Chapters

Data-Driven Testing in Postman

? Data-Driven Testing in Postman

? Quick Overview

Data-driven testing in Postman allows you to run the same API request multiple times using different sets of input data. This is commonly achieved using external data files such as CSV and JSON, making your API tests scalable, reusable, and efficient.

? Key Concepts

  • Collection Runner executes requests using external data files
  • Variables are dynamically replaced per iteration
  • Supports CSV and JSON formats
  • Ideal for bulk testing and validation

? Syntax / Theory

Postman replaces variables like {{variableName}} with values from each row (CSV) or object (JSON) during execution.

? Code Example(s)

? View Code Example
// Access CSV or JSON data variable in Postman
let username = pm.iterationData.get("username");
let password = pm.iterationData.get("password");

pm.environment.set("user", username);
pm.environment.set("pass", password);

? Live Output / Explanation

? What Happens?

For each iteration, Postman injects a new username and password into the request. The same API endpoint is tested repeatedly with different data sets.

? Interactive Example (CSV Structure)

? View Code Example
// Example CSV file structure
username,password
admin,admin123
user1,pass123
user2,pass456

? JSON Data File Example

? View Code Example
// Example JSON data for Postman Runner
[
  {
    "username": "admin",
    "password": "admin123"
  },
  {
    "username": "user1",
    "password": "pass123"
  }
]

? Interactive Simulator: Variable Replacer

Edit the data below and click "Run Runner" to see how Postman replaces variables.

Waiting for execution...

? Use Cases

  • Login API testing with multiple users
  • Bulk data validation
  • Regression testing with varied inputs
  • Negative testing scenarios

✅ Tips & Best Practices

  • Keep variable names consistent with data headers
  • Use JSON for complex nested data
  • Validate responses using tests per iteration
  • Store sensitive data in environments

? Try It Yourself

  1. Create a login API request using variables
  2. Prepare a CSV file with 3 users
  3. Run the collection using Collection Runner
  4. Add assertions for response status and body