{"id":11277,"date":"2022-01-18T19:09:59","date_gmt":"2022-01-19T01:09:59","guid":{"rendered":"https:\/\/threecloud.wpengine.com\/?p=11277"},"modified":"2023-11-21T14:25:24","modified_gmt":"2023-11-21T22:25:24","slug":"automated-api-testing-in-azure-devops","status":"publish","type":"post","link":"https:\/\/3cloudsolutions.com\/resources\/automated-api-testing-in-azure-devops\/","title":{"rendered":"Automated API Testing in Azure DevOps"},"content":{"rendered":"<p>API development is everywhere these days.\u00a0 With Microservice architectures taking off, and JavaScript frameworks needing a way to talk to their servers, writing the server-side code to be exposed through an API is ubiquitous.\u00a0 So when it comes to testing all these APIs to validate that they are running, you need a tool that will easily give you a way to test an API without having to code specific clients to call each API.\u00a0 Postman and it\u2019s command-line-interface partner Newman are just such a tool, and have become a popular tool to have around for just such tasks.<\/p>\n<p>Now, writing scripts in Postman to test out your API is all well and good, and can give you a great way to validate that the API behavior you expect is what you are getting, and also can serve as a way to document what your APIs are doing.. BUT now, how do I get to run those scripts as part of my release pipeline so that I can take advantage of that automation goodness? And while the Postman enterprise accounts will store your scripts, and help you organize them into workspaces, it doesn\u2019t do a wonderful job of keeping history for you.<\/p>\n<p>For Azure DevOps I found a nice little task out in the marketplace to run those Postman scripts through Newman in your build or release pipeline<\/p>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=carlowahlstedt.NewmanPostman\">Newman CLI Task for Azure DevOps<\/a><\/p>\n<p>This task is great, and runs our scripts just as needed.\u00a0 However for our needs, this gave us a great way to run scripts that we have downloaded from Postman, but while we utilize the Postman Enterprise account, we didn\u2019t have a way to run scripts from the Postman Enterprise account directly, requiring us to have a method to pull the scripts down from our Postman account.<\/p>\n<p><strong>So, I\u2019ve created a new task now in the marketplace<\/strong><\/p>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=OneLuckiDev.getPostmanJSON\"><strong>Get Postman Scripts<\/strong><\/a><\/p>\n<p>This task will utilize the Postman API to retrieve the scripts your account has access to.\u00a0 This solves two troubles for us.\u00a0 We can now pull down all the scripts that the QA Team are building in the Postman Enterprise account workspaces so that we have them locally.\u00a0 This means we can easily utilize the Newman CLI task to run our scripts while still giving the QA team the ability to use their Postman Enterprise account.\u00a0 AND it gives us the added benefit of giving us a way to store those scripts in Git so that we have a good history of the scripts.\u00a0 That means if a script worked against a version of an API, and later scripts seem to be incompatible with an API, we can go back! All the benefits of source-control history for our Postman scripts can now be leveraged.<\/p>\n<p>My Get Postman Scripts task will require you to go in to Postman to generate a Postman API credential key token.\u00a0 This will require you to log in to your team\u2019s postman workspaces on the Postman website (I haven\u2019t found a way to do this directly through the Postman client).\u00a0 Then choose the Integrations Tab, and then Browse Integrations, and finally choose the Postman API, from there you can choose to generate an API Key.\u00a0 Keep that key safe and treat it like a password, it\u2019s your access to the Postman API for your credentials.\u00a0 Once you have that key you can enter it to the Get Postman Scripts task in your build pipeline and it should start pulling down scripts for you!<\/p>\n<p><strong>How I\u2019m using this today on a team project:<\/strong><\/p>\n<p>I have created a git Repo to hold our Postman scripts, and I have a Pipeline Build created and scheduled to run weekly for now; we will move it to run more frequently as use of Postman becomes more wide spread.\u00a0 That Build utilizes the Get Postman Scripts task to download the team\u2019s tests from Postman.\u00a0 The build also issues Git commands to keep our Git Repo up to date with the latest scripts.\u00a0\u00a0 In our release pipeline for our APIs, we utilize the Newman CLI task to execute the appropriate Postman tests against the API we released!\u00a0 There you have it, automated API testing through Postman and Newman.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>API development is everywhere these days.\u00a0 With Microservice architectures taking off, and JavaScript frameworks needing&mldr;<\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[381,292],"tags":[385],"class_list":["post-11277","post","type-post","status-publish","format-standard","hentry","category-app-experience","category-app-innovation","tag-devops","topics-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/11277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/comments?post=11277"}],"version-history":[{"count":0,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/11277\/revisions"}],"wp:attachment":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media?parent=11277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/categories?post=11277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/tags?post=11277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}