Deprecated: Function create_function() is deprecated in /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php on line 258

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/qualit96/public_html/wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php:258) in /home/qualit96/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1372
{"id":13330,"date":"2017-07-13T20:09:03","date_gmt":"2017-07-13T15:09:03","guid":{"rendered":"http:\/\/quality-spectrum.com\/?p=13330"},"modified":"2020-02-02T21:14:32","modified_gmt":"2020-02-02T16:14:32","slug":"what-is-api-testing","status":"publish","type":"post","link":"https:\/\/quality-spectrum.com\/what-is-api-testing\/","title":{"rendered":"What is API Testing"},"content":{"rendered":"

In the last post <\/a>we discussed about UI automation and some of its disadvantages. Here we talk about what API level tests are and why to use them.<\/p>\n

What are APIs<\/h2>\n

A<\/strong>pplication P<\/strong>rogrammable I<\/strong>nterfaces (APIs) is an I<\/strong>nterface to help a P<\/strong>rogram (client side programs like browsers, or any other program) access an A<\/strong>pplication. This way the main application is placed on a secure server where all the business logic works and connects with rest of the world using an API. To learn more about the basic concepts, this video<\/a> will help.<\/p>\n

APIs in the context of automation<\/h2>\n

Taking a step back from APIs, let\u2019s illustrate here the different wheels turning behind the scene when a user, fills a form on a website for instance.<\/p>\n<\/div><\/span>

From the image above, when we perform UI automation, we are engaging the Application Under Test (AUT) from step 1 through step 8 all the way, hence another name for UI tests, end to end tests (end to end has a contextual meaning, more on that here<\/a>). Alternatively, we can start our test from step 2 instead, and validate the response at step 7, which is generally called API \/ integration tests. We will be invoking every process along the control flow except steps 1 and 8. In other terms the \u2018client-side\u2019 scripting part is going to be ignored and rest of the application will be tested.<\/p>\n

Automation pyramid<\/h2>\n

As we move from the database level to the browser level (step 4 to 1) automation is going to get more complex for automation and time consuming, with the advantage of testing more technology layers of the AUT. Similarly, in comparing automation from step 1 vs step 2, API tests are going to be less complex and easy to maintain, however we will forego testing certain portions of the AUT. This concept is captured in the phrase \u2018Automation Pyramid\u2019 illustrated below.<\/p>\n<\/div><\/span>

API level tests<\/h2>\n

Since we are not testing steps 1 & 8 we will simulate that functionality performed by our AUT to complete the flow of the application necessitating to understand how our client side scripts are generating messages (POST, GET etc.) sent to the server side. Also in the response, what values are we expecting to receive which would translate into the expected output on the browser\u2019s interface.<\/p>\n

Perhaps this might seem a bit tricky to work on, for most cases its way easier than it sounds. Developers simulate API calls and responses all the time to complete their development. A lot of efficient tools and methods are available to learn how the API is working without need for detailed documentation or insight from the product group (not to say you shouldn\u2019t talk to the dev team, that would kill the whole purpose of testing. Rather it\u2019s not that hard to understand an API from the outside to begin with).<\/p>\n

Uses of API level tests<\/h2>\n

All the drawbacks we discussed in the previous post <\/a>work to the advantage of API tests. These tests compared to UI tests take a lot less time to develop and maintain, more robust due to being less susceptible to change, execute way faster and allow the testers to cover a lot test coverage with the same amount of effort as well.<\/p>\n

Business logic<\/h2>\n

Developers while building the application do not go through the whole control flow every time they test what they just coded. Instead the back-end developers working on the server side just test the API level messages being received and sent. Similarly, the front-end developers working on the client side (front end scripting) would also test their piece of code by simulating API messages. This makes testing both areas (front end and back end) less complex and quick.<\/p>\n

What\u2019s in all of this for the automation guy? We can break down a complex application\u2019s automation into smaller and easier solutions. For applications which are huge, specially having a lot of business logic, it would be a nightmare to have decent code coverage from the UI level. API calls would make that job so much easier and effective.<\/p>\n

Complex UI<\/h2>\n

Sometimes we run into problems on the UI level where certain elements on the web page are not recognized easily by the tool, or do not always perform the way it\u2019s expected by the tool. These tests generally termed as \u2018not automatable\u2019 can be covered from API level tests since we don\u2019t have to deal with the user interface level complexities.<\/p>\n

Service virtualization<\/h2>\n

Many areas of the code need a very specific circumstance to execute which is sometimes very difficult from UI tests. Perhaps there are third party APIs involved, or some external hardware sending in data used by our application, or a piece of code which is scheduled for development in the future needs to be simulated for other teams to complete their feature set. We had a similar problem in one automation project where the server was supposed to receive input data from a hardware device which was still under development.<\/p>\n

On the API level this becomes way lot easier. Mostly in such cases the input \/ output of the API is defined. Lots of tools are out there which can simulate the required calls or responses. It\u2019s then just a matter of constructing the calls properly and validating the expected responses. You might need to create a test harness using other tools \/ frameworks, but it\u2019s a very powerful concept.<\/p>\n

Input for UI tests<\/h2>\n

Creating pre-test data and \/ or removing it at the end of the test can becomes a problem. API level tests can be very effective for test data management. Again one or more structured API requests would do the trick in no time. Similarly, for deleting data which is no longer needed should be equally simple (except where business logic is complex enough blocking the removal of a record by simply one call).<\/p>\n

Would love to hear what other uses you can think of API tests.<\/p>\n<\/div>

<\/div><\/div><\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":13333,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[44],"tags":[],"yoast_head":"\nWhat is API Testing - Quality Spectrum<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/quality-spectrum.com\/what-is-api-testing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is API Testing - Quality Spectrum\" \/>\n<meta property=\"og:url\" content=\"http:\/\/quality-spectrum.com\/what-is-api-testing\/\" \/>\n<meta property=\"og:site_name\" content=\"Quality Spectrum\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-13T15:09:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-02T16:14:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/quality-spectrum.com\/wp-content\/uploads\/2017\/07\/Code.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2300\" \/>\n\t<meta property=\"og:image:height\" content=\"949\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@aali_khalid\" \/>\n<meta name=\"twitter:site\" content=\"@aali_khalid\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/quality-spectrum.com\/#organization\",\"name\":\"Quality Spectrum\",\"url\":\"https:\/\/quality-spectrum.com\/\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/alikhalid\/\",\"https:\/\/www.youtube.com\/c\/QualitySpectrum\",\"https:\/\/twitter.com\/aali_khalid\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/quality-spectrum.com\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/quality-spectrum.com\/wp-content\/uploads\/2019\/11\/QS-logo-mobile-e1574510459832.png\",\"width\":40,\"height\":40,\"caption\":\"Quality Spectrum\"},\"image\":{\"@id\":\"https:\/\/quality-spectrum.com\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/quality-spectrum.com\/#website\",\"url\":\"https:\/\/quality-spectrum.com\/\",\"name\":\"Quality Spectrum\",\"description\":\"Redefining software quality\",\"publisher\":{\"@id\":\"https:\/\/quality-spectrum.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/quality-spectrum.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/quality-spectrum.com\/wp-content\/uploads\/2017\/07\/Code.jpg\",\"width\":2300,\"height\":949,\"caption\":\"Programming code abstract technology background of software developer and Computer script\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#webpage\",\"url\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/\",\"name\":\"What is API Testing - Quality Spectrum\",\"isPartOf\":{\"@id\":\"https:\/\/quality-spectrum.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#primaryimage\"},\"datePublished\":\"2017-07-13T15:09:03+00:00\",\"dateModified\":\"2020-02-02T16:14:32+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/quality-spectrum.com\/what-is-api-testing\/\"]}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#webpage\"},\"author\":{\"@id\":\"https:\/\/quality-spectrum.com\/#\/schema\/person\/4805a00d7139e111ea9430e17cc8f28c\"},\"headline\":\"What is API Testing\",\"datePublished\":\"2017-07-13T15:09:03+00:00\",\"dateModified\":\"2020-02-02T16:14:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#webpage\"},\"commentCount\":8,\"publisher\":{\"@id\":\"https:\/\/quality-spectrum.com\/#organization\"},\"image\":{\"@id\":\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#primaryimage\"},\"articleSection\":\"API Testing\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/quality-spectrum.com\/what-is-api-testing\/#respond\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/quality-spectrum.com\/#\/schema\/person\/4805a00d7139e111ea9430e17cc8f28c\",\"name\":\"Ali Khalid\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/quality-spectrum.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70cbf539f218f275a77959dd2e56bddb?s=96&d=mm&r=g\",\"caption\":\"Ali Khalid\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/posts\/13330"}],"collection":[{"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/comments?post=13330"}],"version-history":[{"count":2,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/posts\/13330\/revisions"}],"predecessor-version":[{"id":15056,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/posts\/13330\/revisions\/15056"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/media\/13333"}],"wp:attachment":[{"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/media?parent=13330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/categories?post=13330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/quality-spectrum.com\/wp-json\/wp\/v2\/tags?post=13330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}