Data-Driven Tests

Learn how to repeat tests with different data.

Working with data files

The Collection Runner and Newman allow us to run tests using data files. A data file can be in CSV or JSON format containing a list of test data. The following is a JSON example:

Press + to interact
[
{
"scenario": "positive: create account",
"password": "3le!wAl2",
"status": 200,
"message": null
},
{
"scenario": "negative: missing password",
"status": 400,
"password": "",
"message": "password is required."
},
{
"scenario": "negative: null username",
"username": "",
"password": "alSkjf$c",
"status": 400,
"message": "username is required."
},
{
"scenario": "negative: duplicate username",
"password": "weuy#Dv3",
"status": 409,
"message": "entered username already in use."
}
]

We can use the code above to test the sign-up endpoint for the login application with different values. We would use the data in the file to populate values for associated variables in the request scripts. This feature is great when we want to test the same request multiple times against different data sets. In the example above, there would be four test runs (i.e., iterations) because there are four data objects in the file.

Start the application

Execute the application below to start the Postman app:

Press Run to load Postman
Postman and login applications
...
Access this course and 1400+ top-rated courses and projects.