API Testing 'A Beginners View': Data-driven testing in Postman

Hi Everyone!!! Let’s check out some details about Data-Driven Testing with Postman using CSV and JSON files😊

Data-driven testing can be a very effective approach in testing an API against different data-sets. Postman supports CSV and JSON files to get data for the test scripts. The data-driven approach is useful when we need to execute a test with multiple sets of Data. Also, modifying or adding any data fields will just need updating the data files which is easier than going to test script and updating test data.

To explain the same I’ll use a sample request which I use in my daily work.

Steps to do this:-

  1. Now, in this example, I want to refer Row_No, UCI_Number, and Entity_ID from a CSV file. So, as a pre-requisite, we need to define these in a variable. In order to do so in the Pre-request Script tab we need to set the variables as in the screenshot, so that going ahead values will be read from variables.
  2. Create a CSV file having these variables and values.
  3. Now go to Collection Runner, and import this data file and click on the Run button. Data File Preview:

After hitting on the run:

Run can be stopped any time of execution:

With JSON data file: Now, let us do the same thing with the JSON file. Create a new JSON file, and in Collection, Runner uses this JSON file.

Sample JSON File:

After a run of a JSON data file:

That’s it, and now we have some insight into the Data-Driven Testing with Postman using CSV and JSON files.

Some interesting yet important notes related to the Data-Driven approach:

Note: We can randomly retrieve data from CSV data files in a data-driven approach.

The Approach to Note: Recently in my daily work had a scenario, wherein I had to randomly fetch data from the CSV data file and perform my test. Then found a way out to solve it. Here is what I did! The explanation is below:

  • In Pre-request I fetched the total records and used in the Test script to do my testing

//Finding the total number of iterations that are scheduled to run since Total number of iterations === Number of rows in your CSV File

var list = pm.info.iterationCount;


pm.environment.set(“Total_Records”, list);

  • In Test script I checked the modulo value and did the tests as needed >> IF ($rownumber%(square root of the total number of records in file))=0 {do you test} else {postman.setNextRequest(null);}

Hope this article was interesting. Let me know if this was helpful.

Can check the same article on my Personal BLOG too…

Happy Learning :innocent:

1 Like

Love it! Thanks for sharing :slight_smile:

1 Like

@hannah.neil thanks you

1 Like