Keys to Workplace Wellness Part 3 – Spiritual Wellness
January 29, 2021Auto Format Your Code with ESLint
March 9, 2021Lately, our team has been streamlined the development of our larger systems by integrating our tests into an automated commit process. We have implemented a few test suites over the year, including unit tests, regression tests, and UI tests. Having tests are great, but as we use them during our development they slow us down getting new code committed to Git. Our Regression Test suite is created with Postman Collections and run after an app is built. Learn more about creating Postman Collections here. With our apps growing larger and larger, we’ve had to create larger and larger test Collections.
And with larger Collections comes great responsibility.
After working with large Collections and possibly more confusing environment variable files, I wanted something better to work with.
So I found a great NPM Module Newman-Run that will use a feed file to run any number of Collections paired with environments asynchronously. A feed is a JSON file with arrays that reference the collection and environment used for the Newman run. This feed file has made it so we can break out our huge Collections into several smaller, more manageable Collections. With this change to the collections, we can break them into smaller more succinct tests for sections of the app. The module uses a feed file for you to reference your Collection and environment variables files that you want run. A feed file looks like:
{
"runs":[
{
"collection": "./reference/PostmanRegressionTesting/Initial-Scenarios.postman_collection.json",
"environment": "./reference/PostmanRegressionTesting/Development.postman_environment.json"
},
{
"collection": "./reference/PostmanRegressionTesting/Global-Tests.postman_collection.json",
"environment": "./reference/PostmanRegressionTesting/Development.postman_environment.json"
}
]
}
When Newman-Run calls this file it makes ‘runs’ that are Collection and environment pairs that run your tests where you want them run. It uses Newman to run your tests, but it runs them asynchronously on your machine. Running these asynchronously means they will be run at the same time, completing them faster. We have seen them run faster by a factor of two on our machine, but the speed is based on how many you run at once in your feed file. Once you have your runs ready in the feed file, the Newman-Run command is very simple:
newman-run -
f <FeedFile.json>
As they run you will get the output Newman normally creates. When a test fails it will show you, in length, what the problem was. So you can troubleshoot how to correct it.
This has been a great module for us to speed up our testing integrations and I hope it will help yours as well!
4 Comments
Hi Adam, I am trying to run multiple collections using this feed file method but it is not working for me. Can you help me, please? And “newman-run -f ” this command is not recognized by Newman. As far as I know it should be newman run not newman-run.
Thanks for the question! It is
newman-run
and not a space in between, you are calling the NPM Module name to run the tests. The newman-run command you are using will need the path to the json feed file you created like this:newman-run -f /test/RunAllTests.json
. It will take the ‘runs’ you created in that file and run those tests!In a feed file, to provide the location of the env file we use the “environment” tag.
How to provide a data file here??
Each run in the `feed.json` you will need to get the correct path to each environment file. If you are having trouble finding the path of the file, try moving it to the same directory as the collection and see if you can load it then.
If the data file is not loading, it is an export from Postman that is a JSON file showing the variables used in that environment. You can export your environment from Postman, but it is a simple JSON file you could create in a text editor, like this:
{
"id": "fe93ce4b-234a-4944-a701-0cab72ba3c2f",
"name": "Localhost",
"values": [
{
"key": "appURL",
"value": "http://localhost/index.html",
"enabled": true
},
{
"key": "testingVariable",
"value": "1234",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2021-06-22T17:25:21.331Z",
"_postman_exported_using": "Postman/7.14.0"
}