{"id":30,"date":"2022-10-26T19:21:24","date_gmt":"2022-10-26T19:21:24","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/cozycoder\/?p=30"},"modified":"2022-10-26T19:21:24","modified_gmt":"2022-10-26T19:21:24","slug":"api-testing","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/cozycoder\/2022\/10\/26\/api-testing\/","title":{"rendered":"API Testing"},"content":{"rendered":"\n<p>I&#8217;m sure most of us aspire to use a Test-Driven Development approach to our coding &#8211; it forces clarity on requirement definition and can be invaluable in supporting alignment between team members\/different services for an app. This would typically take the form of unit testing but, to test the full functionality of an API endpoint it requires a slightly different set of tools. <\/p>\n\n\n\n<p>As my capstone team continues work on our own API we want to make sure we hand off a complete set of tools to our industry partner at the end of the project &#8211; including an API test suite. So &#8211; which tool to use? Through our own professional and academic experiences with these tools, we are currently deciding between two tools &#8211; Postman and Swagger. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"376\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/image-1024x376.png\" alt=\"\" class=\"wp-image-32\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/image-1024x376.png 1024w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/image-300x110.png 300w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/image-768x282.png 768w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/image-1536x564.png 1536w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/image-2048x752.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Postman Suite of Tests<\/figcaption><\/figure>\n\n\n\n<p>Postman offers a friendly UI that can be completely separate from the app repository\/deployment. Postman allows you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>import both an environment and a test suite<\/li><li>define multiple tests for the same endpoint<\/li><li>set local or environmental variables &#8211; both before and after calls<\/li><li>run an entire suite of tests with a single click<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"987\" height=\"425\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/swagger.png\" alt=\"\" class=\"wp-image-31\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/swagger.png 987w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/swagger-300x129.png 300w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5899\/files\/2022\/10\/swagger-768x331.png 768w\" sizes=\"auto, (max-width: 987px) 100vw, 987px\" \/><\/figure>\n\n\n\n<p>Alternatively, Swagger is more closely integrated with the code itself. Swagger allows you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>define parameters, descriptions, and defaults using decorators directly within the code<\/li><li>perform manual testing in a user-friendly GUI where both the response and request are clearly laid out, side by side<\/li><\/ul>\n\n\n\n<p>Both tools offer automated testing tools &#8211; helpful for integration or reliability testing &#8211; and have similar price points. Assuming that running the app (or accessing its deployment) is trivial &#8211; Swagger offers a very friendly UI and makes it easy to incorporate Swagger documentation into coding comments and code review. It does require a &#8220;home&#8221; for the GUI but can be nicely incorporated into a team&#8217;s wiki. Postman feels like a more compartmentalized option &#8211; assuming the users have some familiarity with Postman, importing the environment and test collection is easy. <\/p>\n\n\n\n<p>For my team&#8217;s use case &#8211; where we will not be maintaining the project in the long-term &#8211; Postman seems like the logical choice since we don&#8217;t know how our industry partner will ultimately deploy the app and Postman&#8217;s environment configurations are easily changed. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m sure most of us aspire to use a Test-Driven Development approach to our coding &#8211; it forces clarity on requirement definition and can be invaluable in supporting alignment between team members\/different services for an app. This would typically take the form of unit testing but, to test the full functionality of an API endpoint &hellip; <a href=\"https:\/\/blogs.oregonstate.edu\/cozycoder\/2022\/10\/26\/api-testing\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">API Testing<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":12652,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/users\/12652"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/posts\/30\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/cozycoder\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}