Your Guide to API testing: Postman, Newman & Jenkins

API testing is a type of software testing wherein an engineer tests not just the functionality but performance, reliability and security for an application. APIs are tested to examine if the application would work the way it is expected to, as APIs are the core of an application’s functionalities.

What Is API Testing?

API testing during development can reveal issues with API, server, other services, network and more, those which one may not discover or solve easily after deployment.

However, testing APIs is difficult. Instead of just verifying an endpoint’s response, one can have integration tests with Postman to examine and validate the responses. Teams these days may also want to automate running these tests as soon as a deployment is done. One approach we can take is to have our integration tests run every time a developer checks in code to the repo.

Adding this layer of Quality check, can ensure that the existing functionalities still work the way they were expected to, with an additional benefit for the developers to validate that their code is doing exactly what it was intended to.

Tools for API test automation in CI

CI refers to continuous integration. Integration of test scripts and a test tool with the continuous build system where the test scripts can be run along with every new deployment or on a regular basis (daily, weekly or fortnightly)

  1. Postman: Integration tests with Postman.
  2. Newman: Create a PowerShell file that runs these integration tests via command line.
  3. Jenkins: Add a Post Build step in Jenkins to execute the PowerShell script whenever a build is initiated.

How to use Postman with Newman & Jenkins for Continuous Integration

 

API Selection

I have implemented this procedure in our Project using the GPS APIs, but for instantiating here, let’s take up the following APIs:

Open Weather Map: Free public APIs.

I chose this as it is a free collection of APIs that anyone can subscribe to and have their own API keys to operate with.

Create Integration Tests

For the first test, let’s take up a simple GET request to get Weather by ID. To interact through the APIs, make sure to use the API key received on subscribing to the OWM services.

Steps to First Integration Test

Make an environment on Postman say, ‘Weather Map’ and define the environment variables in it. [Refer ‘Managing environments’].

Add the Prerequisites in the Pre-Req tab to set up the test.

Collections

Like the above API tests, one can have multiple test scripts for multiple endpoints. And these multiple test scripts can be run in sequence to have an end to end test suite. The way to have a test suite is to keep multiple test scripts in a place holder called as a Collection in Postman.

These collections can then further be executed through the collection runner in the tool.

Collection Runner

A collection runner can be used to have a collection of API endpoints with their test scripts at one place and therefore run them one by one in a sequential manner. The user just needs to run the collection just once with all the required test data, test scripts and for as many iterations one may want. The result of the collection run is a test report, comprehensive enough to monitor the performance of the APIs and also to re-try running the failed test scripts.

For elaborate study on Collection Runners, refer Link.

Though the user interface of Postman’s collection runner is good enough, yet, to integrate the system with Jenkins, we need to run our collections via command line. So, a way to run collections via the command line is through Newman.

Newman

Newman is a Node Package Manager (NPM) package that permits us to run and test collections directly from the command line.

Pre-requisites:

  • NodeJS and
  • NPM already installed.

Commands to be run on Windows Powershell

  • node -v [to verify the version of NodeJs installed]
  • npm -v [to verify the version of NPM installed]
  • $npm install -g newman [to install Newman]

Once the required installations are done, one needs to have his collections and Environment exported to JSON files in the local system. These files can then be passed as arguments to Newman.

Steps to get the environment and collections on the local system:

  • Click on the Download and Export button in Postman.
  • Download the collection
  • Download the environment
  • Open command prompt and raise your privileges. This is important for you to execute the script.

Adding Postman Tests to Jenkins

Testing REST APIs with Newman | R-bloggers

We first need to export our Postman files (Environment and Collections) and add them to GIT, along with our Powershell script to run the tests through Jenkins build.

“Add the Postman files to the root of the project.”

Telling Jenkins to run Newman

For this we write a script that calls Newman and passes it the Environment and Collection JSON files.

–  ‘exit $LASTEXITCODE’: On typing this command, you will see the result of the last command. We do this to make sure that on every loop, the Newman command is successful. If any of the tests fail, we have to stop the script and exit 1. It will result in a failed build on Jenkins.

Adding Script to Jenkins

Steps:

  • Login to Jenkins and create a Freestyle Project.
  • Start by configuring this project to pull your repo code from Git.
  • In the General Tab, go to build section

Running the build and monitoring Results

Try running the project and examine the results.

One can make out successful entrance into the powershell script with the statement ‘Inside Powershell script’ in the Jenkins output.

Conclusion

Improving continuous integration utilizing Postman, Newman and Jenkins adds another layer of quality assurance into our development life cycle. While this is a huge step in automation, we need to emphasize on the fact that our test coverage depends on the quality of our test scripts.

Share:

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn
<b><strong>Karan Makan</strong></b>

Karan Makan

Technology Engineer and Entrepreneur. Currently working with International Clients and helping them scale their products through different ventures. With over 8 years of experience and strong background in Internet Product Management, Growth & Business Strategy.

PrevPreviousA Digital Divide has emerged as a result of Remote Working
NextDesign ‘THE’ Patient EngagementNext
error: Content is protected !!

4617作文网怎么给公司产品起名字女孩取名起名大全yi字大全周公解梦姐妹女孩儿生辰八字属火起名姓岳起姓名大全淑字起名女孩名字机器人培训机构起名爸爸姓李妈妈姓崔孩子起名字梦见吃鸡肉什么预兆周公解梦听起来大气的取名八字算命万年历姓卜宝宝起名火烧店起名大全公司起名吉祥字2020陈起哪个名字好听在线起名测名打分测试济南周易选日子周易八字排盘免费猪小儿起名注意事项泰迪一般都起什么名字啊周公解梦梦吃包子周易取名好么周公解梦梦见好多珏起名字配什么字好公司取名起名大全打分测试1518算死命免费阅读全文下载算死命五行查询周易姓名大师八字命理测算设备经济寿命计算公式谁能帮我起一个名字英文的淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男子给前妻转账 现任妻子起诉要回网友建议重庆地铁不准乘客携带菜筐月嫂回应掌掴婴儿是在赶虫子重庆警方辟谣“男子杀人焚尸”国产伟哥去年销售近13亿新的一天从800个哈欠开始男孩疑遭霸凌 家长讨说法被踢出群高中生被打伤下体休学 邯郸通报男子持台球杆殴打2名女店员被抓19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警两大学生合买彩票中奖一人不认账德国打算提及普京时仅用姓名山西省委原副书记商黎光被逮捕武汉大学樱花即将进入盛花期今日春分张家界的山上“长”满了韩国人?特朗普谈“凯特王妃P图照”王树国3次鞠躬告别西交大师生白宫:哈马斯三号人物被杀代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了房客欠租失踪 房东直发愁倪萍分享减重40斤方法“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火手机成瘾是影响睡眠质量重要因素考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼网友洛杉矶偶遇贾玲呼北高速交通事故已致14人死亡西双版纳热带植物园回应蜉蝣大爆发男孩8年未见母亲被告知被遗忘张立群任西安交通大学校长恒大被罚41.75亿到底怎么缴沈阳一轿车冲入人行道致3死2伤奥运男篮美国塞尔维亚同组周杰伦一审败诉网易国标起草人:淀粉肠是低配版火腿肠外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万杨倩无缘巴黎奥运男子被猫抓伤后确诊“猫抓病”春分“立蛋”成功率更高?记者:伊万改变了国足氛围奥巴马现身唐宁街 黑色着装引猜测

4617作文网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化