Why do we need API testing?
Why do we need API testing?
Initially, you have to understand what the API is and what exactly it issued for. Most modern applications are created on the basic principle of a Client-Server architecture building. This means that the service (a program or an application) is divided into two main components: a graphical interface (a client) and a business-logic plus a database (a server).
In turn, the client and the server interact with each other using the API (Application Programming Interface). The API can be compared with a waiter in a restaurant – it serves as a mediator between the one who orders food and the kitchen that prepares it. It delivers the order to the kitchen and then brings the dish to the client. The more customers there are in a restaurant, the more waiters are needed.
In the same way, and as a rule, various people are involved in the development of the client and server. These are the Front-end and the Back- end Developers, each of which may use a different programming language.
The workflow is described within the following framework:
A Back-end Developer (the server) starts creating the business logic of the required server in order to meet requirements. Normally, he does not pay too much attention to the design, which may not be ready at the beginning of the development.
A Front-end Developer then starts working on a certain module at a time when both the business logic from the server side and the design are ready.
At this point, the most interesting thing happens:
The “Server” sends the API to the “Client” with complete confidence in its functionality, but it turns out that a Front-end Developer, for a number of reasons, cannot use it.
Among such reasons might be:
- The API is not applicable to the design;
- Some bugs, which were not detected earlier, had occurred in the server;
- All necessary scenarios of user behavior are not processed;
- Unstable behavior with an increasing load on the server;
- Many other unforeseen factors.
As soon as a Front-end Developer faces any of the above-mentioned problems, his work stops being performed. He reports the problem to a Back-end Developer and waits for the problem to be fixed.
In turn, a Back-end Developer postpones the current module and returns to the previous one for the correction. It is quite probable that changes in the logic of the previous module can affect the subsequent ones. As a result, the development process is prolonged on a rather extended period, which leads to an unexpected and long-lasting error correction.
So, what do you do? How do you avoid such situations? The answer is fairly simple, the API testing should be conducted at the early stages of development. A Front-end Developer should not even start working before the tester has checked the server part for compliance with the requirements.
Due to the destructive behavior of the QA engineer, most of the bugs can be detected and corrected at the early stages of development. Additionally, a tester must perform load testing of the most “labor-intensive” parts of the API, as making changes will not lead to violations of the terms of work performance.
Furthermore, there are cases when the creation of the current module can negatively affect the work correctness, the previously created function or a method. Such mistakes could be hidden for a long time in a lot of new lines of program code and might be found at the most inappropriate moment.
Due to modern testing, this problem can be avoided by creating automatic tests for the API in particular. Having created the auto-tests once, one can use them an unlimited number of times. It may be conducted both at the development stages and at the final stages of regression testing with transfer of the final product to a customer. It is obvious that writing auto-tests is time-consuming, but it remains important to analyze the results of implementation. This ultimately saves time for both testers and programmers.
If you summarize all of the above, you can identify the main reasons for testing the API:
- Saving developer’s time!
- Possibility of finding defects in early stages;
- Reducing the number of manual tests;
- Identifying more errors;
- Reducing the time required for regression testing;
- Confidence in the program capabilities at any time.