Nowadays, almost every application that is being built relies on APIs. This makes it a big priority to verify those APIs before releasing a product to the end users. In addition, testing APIs is much less expensive than doing UI or E2E testing.
However, properly testing and automating the tests for APIs is still ignored in several development projects. In this article, we will explain why API testing is so important and how to make it happen. We will also discuss using a built-in tool or a custom framework.
What is API testing and why is it important?
To test an Application Programming Interface (API) we essentially send HTTP requests (GET, POST, PUT, PATCH, DELETE) to the API, validating the API’s response. We usually validate response contents, HTTP status codes, response data formats, correctness, and validation errors.
We don’t test third-party APIs, but we can test the way our software accepts their requests. In this article, we’ll focus on in-house web APIs and their quality assurance.
Regarding the importance of automating API tests, we need to think about the test pyramid. The base of the pyramid mentions those automated tests we need the most that are fast and reliable. Those are the unit tests that are usually written by developers. Next level in that pyramid are Service (API) and Integration tests. They are not as fast as unit tests but are still good candidates because fewer tests are needed. Finally, we have E2E tests that are slower and less reliable than the other two types in the pyramid, and in consequence, we should select the best candidates for that.
By doing API testing, we start testing at the early stages. If the request does not return the needed value at the server layer, it will not be displayed at the UI layer either. Not relying on UI to be ready, API tests can be performed early in the development cycle.
This way, they will kill at least half of the bugs before they get serious. If we also consider that they are quicker to create, easier to maintain, faster to run, and more reliable than UI/E2E testing, then what are you waiting for to start testing APIs?
That being said, it is important to clarify that we don’t dismiss UI testing. Certain defects can only be caught by GUI tests or E2E tests, and they are the only test types that truly test the user experience. So, we are not replacing one with the other — they are complementary.
This might be interesting: API- Led Connectivity: Key steps to move towards this approach
API testing framework vs ready-made API testing tool
When automated, API testing can be easily performed on a regular basis. Its main advantage is speed — less lag time between development and QA and less time spent on debugging in production.
QA engineers perform automated API testing using a testing tool that drives the API. We will discuss the most popular solutions.
When choosing among the tools to use, keep in mind that some of them are better for writing an automation framework (RestSharp, REST Assured, Requests), while others (Postman, SoapUI, Katalon, jMeter) can be utilized as they are – built-in tools.
Let’s look at some pros and cons for each approach.
Writing your own framework
Pros we can find:
- Freedom: You are not limited to the capabilities of a tool. You can extend your framework as much as the language you are using allows you.
- Code reusability: A well-designed framework would allow you to solve custom problems from your domain/application and reuse that code for every test you may need.
- Scalability: A framework allows you to scale your project as much as needed when you organize and plan it accordingly.
- Maintainability: When changes appear on the API (they are going to appear), by coding your own framework, it is much easier to modify your tests and code than any built-in tool.
- CI/CD: Some tools also include this, but most of them are paid versions.
- Custom reports: These show results and information in the way we and our customers need.
And cons to consider:
- Strong coding skills are needed.
- It takes a lot of time to start up until we can write our first test.
- It depends on the library the community has chosen, but it could be reduced, thereby making it hard to get answers for questions that may arise.
Do not miss this: When would you use REST API?
- It has a user-friendly interface that is easy to learn and can be used from the beginning.
- There is a short time to start. In a matter of minutes, you can write your first test.
- Almost no coding skills are required, which allows any team member to create, modify, and run tests.
- These kinds of tools have official support.
And the cons here are the pros of a framework:
- They are hard to maintain.
- They have low scalability.
- The code is not reusable.
We can conclude that a built-in tool like Postman could be a good solution for starters or for small projects that just need a limited number of tests or that will last just a few months. For bigger projects or long-term projects, building your own framework is the only way to really achieve success with API test automation.
Want to know more about our testing services? Go ahead and get in touch with us!