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 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 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 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> 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>\nWhat are APIs<\/h2>\n
APIs in the context of automation<\/h2>\n
Automation pyramid<\/h2>\n
API level tests<\/h2>\n
Uses of API level tests<\/h2>\n