Postman data-driven tests let you run the same API request multiple times with different sets of input data, making your testing much more efficient and comprehensive.
Let’s see this in action. Imagine you have a simple API endpoint that creates a user:
POST /users
And it expects a JSON body like this:
{
"name": "John Doe",
"email": "john.doe@example.com"
}
Instead of manually changing the name and email in the Postman request body for each test, you can use a CSV file.
1. Create your CSV file:
Let’s call it users.csv and put it in a directory like /path/to/your/data/.
name,email
Jane Smith,jane.smith@example.com
Peter Jones,peter.jones@example.com
Alice Brown,alice.brown@example.com
2. Configure Postman:
In your Postman collection, go to the Authorization tab (or wherever your request is). Click on the … next to your collection name and select Import. Choose Data and then select your users.csv file. Postman will prompt you to select the delimiter (comma for CSV) and then import the data as a collection variable.
3. Use variables in your request:
Now, in your POST /users request’s body, replace the hardcoded values with Postman variables:
{
"name": "{{name}}",
"email": "{{email}}"
}
4. Run the collection with data:
Click the Run button for your collection. In the runner window, you’ll see your users.csv file listed under "Data File". Postman will automatically detect the columns and offer to use them as variables. Select your CSV file and ensure the variables {{name}} and {{email}} are mapped correctly. Click Run [Your Collection Name].
Postman will now execute your POST /users request once for each row in your users.csv file, substituting {{name}} and {{email}} with the values from each row. You’ll see results for each iteration in the runner.
This approach is incredibly powerful for testing edge cases, different user roles, or various data permutations without repetitive manual work. You can also use JSON files for data-driven tests, which can be more flexible for complex nested data structures.
The most surprising aspect of data-driven testing in Postman is how seamlessly it integrates variables directly into your request body, headers, or URL parameters without requiring any complex scripting for basic data substitution. It feels like magic when you first see it, but it’s just smart variable handling. You can even use the pm.variables.get() function in your pre-request scripts or tests to access these data variables programmatically, allowing for more dynamic test logic based on the current data row.
The next logical step is to start chaining these requests together in a collection, where the output of one data-driven request becomes the input for another.