Postman tests in Jenkins
Integration of postman collection for REST API testing into Continuous Integration flow
Postman collection. Definitions
● Request (defined REST API request with a set of validation tests)● Folder (set of Requests)● Collection (set of Folders and Requests)
Collection should be considered as “root” folder for your project. Folders can be used to organize requests by component, by feature, by date or any other groups.
How to integrate created tests in CI?
● Export environment variables● Export collection● Push exported files to Git (or other VCS)● Install NodeJS and NPM on your CI server● Install newman on CI server● Add CI job (or task/action/rule depending on CI terminology) to run newman
after deploying your REST API
Install prerequisites
● NodeJS and NPM https://nodejs.org/en/download/● Newman command line tool https://www.npmjs.com/package/newman● Git
NOTE: these tools should be installed on your CI server (e.g. Jenkins)
Jenkins plugins to install
● Email Extension Plugin● Git plugin (in most cases is installed by default)
Steps for adding Jenkins job
1. Create job with desired name and “Freestyle project” type;2. Enter URL for your git repository under “Source Code Management”;
a. Add credentials in case you are using private git repository;b. Specify branch you would like to use (“master” by default)
3. Click on “Add Build Step” > “Execute shell” under “Build” section.4. Type newman command to run collection (newman run <collection_file_name> -e
<env_var_filename>)5. Configure Email Notification under “Post-build actions” section.6. Configure your deployment job to trigger
● Open your existing Job (the one that is used for application deployment)● Click on “Configure”● Select “Build other projects” under “Post-build Actions” section● Enter name of your job with newman command● Save
Trigger your new job from another
What we have used?
Summary of the tools used
● Postman for creating tests● Newman for running them on
server● Git for storing your collections
and variables’ file● Jenkins to trigger newman
command in certain conditions (after deployment, daily, on demand, etc)
ThanksQuestions?
Example files used in presentation can be found at https://github.com/qaclub/postman_collection_example