Newman + Postman tests in CircleCI
Alexander Lazaris
Posted on February 9, 2021
Running Postman tests in CircleCI
Ready the collection
- stored all urls + auth values as environment variables, ensuring each hardcoded value is replaced by it's respective variable
- added validations after each request to test status code + pass through response values
- export postman collection to a new folder. Hint: This new folder will become the git repo folder
var jsonData = JSON.parse(responseBody);
if (jsonData.access_token) {
pm.environment.set("user_access_token", jsonData.access_token);
}
pm.test("Status code is 200");
pm.response.to.have.status(200);
Newman ....
npm init
npm install newman
- test run the collection using
./node_modules/.bin/newman run collectionfile.json
- each env variable won't have a value at this point. To populate them, append
--env-var envVariableName=envVariableValue
to the run cmd above. These will later be added + stored in CircleCI. - add
npm test
which contains the full run cmd above - stored all of the above files in a git repo and pushed
`"test": "newman run 'postman_collection.json' --env-var --reporters junit,cli"
Is it coming together now?
- sign up to circleci using GitHub
- create project linked to github repo
- create
config.yml
file which contains circleci instructions. Use a Node template provided circleci or create your own. - create env variables in CircleCI project, matching the exact name they had in Postman AND in
npm test
had to include screenshot of
config.yml
contents as I don't know how to retain indenting in markdown
Time to trigger the tests
- the lovely feature of building for each PR commit is enabled by default in circleci
- final directory files + folders is clean & minimal. Mine is:
- trigger a build by committing to the repo
End result:
Well, apart from the failed test due to bad test data, it all worked as expected!
💖 💪 🙅 🚩
Alexander Lazaris
Posted on February 9, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.