An API is essentially the “middle man” of the layers and systems within an application or software.
API (application programming interface) testing is performed at the message layer without GUI. It is a part of integration testing that determines whether the APIs meet the testers’ expectations of functionality, reliability, performance, and security.
There are two broad classes of web services for Web API: SOAP and REST.
SOAP (Simple Object Access Protocol) is a standard protocol defined by the W3C standards for sending and receiving web service requests and responses.
REST (Representational State Transfer) is the web standards-based architecture that uses HTTP. Unlike SOAP-based Web services, there is no official standard for RESTful Web APIs.
Read More: What is API? A Clear and Simple Explanation With 10 Examples
Here are 10 basic tips that you need to know for API testing:
Before testing your APIs, you need to answer these questions to thoroughly understand the API’s requirements:
Knowing the purpose of the API will set a firm foundation for you to well prepare your test data for input and output. This step also helps you define the verification approach. For example, for some APIs, you will verify the responses against the database; and for some others, it is better to verify the responses against other APIs.
Generally, APIs of an application are used to manipulate its resources in reading (GET), creating (POST), updating (PUT) and deleting (DELETE). Knowing the purpose of the API will set a firm foundation for you to well prepare your API testing data for input and output.
In addition, this step also helps you define the verification approach. For example, for some APIs, you will verify the responses against the database; and for some others, it is better to verify the responses against other APIs.
For example, the output of the “Create user” API will be the input of the “Get user” API for verification. The output of the “Get user” API can be used as the input of the “Update user” API, and so on.
Read More: What is an API Sandbox?
The most common API output you need to verify in API testing is the response status code.
Verifying if the response code equals to 200 or not to decide whether an API testing is passed or failed is familiar to new API testers. This is not a wrong verification. However, it does not reflect all test scenarios of the API.
All API response status codes are separated into five classes (or categories) in a global standard. The first digit of the status code defines the class of response. The last two digits do not have any class or categorization role.
There are five values for the first digit:
However, the actual response status code of an API is specified by the development team that built the API. So as a tester, you need to verify whether:
In a testing project, there are always some APIs that are simple with only one or two inputs such as login API, get token API, health check API, etc. However, these APIs are necessary and are considered as the “gate” to enter further APIs. Focusing on these APIs before the others will ensure that the API servers, environment, and authentication work properly.
You should also avoid testing more than one API in a test case. It is painful if errors occur because you will have to debug the data flow generated by API in a sequence. Keep your testing as simple as possible. There are some cases in which you need to call a series of API to achieve an end-to-end testing flow. However, these tasks should come after all APIs have been individually tested.
Read More: Sample Test Cases For API That You Will Need (With Test Case Template To Download)
A testing project may have a few or even hundreds of APIs for testing. We highly suggest that you organize them into categories for better test management. It takes one extra step but will significantly help you create test scenarios with high coverage and integration. Take JIRA’s API, for example:
APIs in the same category share some common information such as resource type, path, etc. Organizing your tests with the same structures will make your test reusable and extendable with integration flow.
Read More: Top 30+ Web API Testing Interview Questions
Leverage automation to speed up your API testing process as much and as early as possible. Here are some significant benefits of automating API tests:
There are 2 approaches for you to choose from:
A further step to leverage the automation capability of API testing is choosing the most or a set of suitable API testing tools from hundreds of options in the market. Here are some criteria that you should consider when choosing an API testing automated testing tool:
|
|
This is an essential task since you cannot start testing an API without authorization.
While the response status code tells the status of the request, the response body content is what an API returns with the given input.
An API response content varies from data types to sizes. The responses can be in plain text, a JSON data structure, an XML document, and more. They can be a simple few-word string (even empty), or a hundred-page JSON/XML file. Hence, it is essential to choose a suitable verification method for a given API.
Katalon Studio has provided rich libraries to verify different data types using matching, regular expression, JsonPath, and XmlPath.
Generally, there are some basic methods to verify an API response body content:
This method is suitable for a simple response with static contents. Dynamic information such as date time, increasing ID, etc. will cause trouble in the assertion.
For those responses in JSON or XML format, it is easy to get the value of a given key or attribute. Hence, this method is helpful when verifying dynamic content, or individual value rather than the whole content.
Together with verifying individual attribute values, this method is used to verify data responses with a specific pattern to handle complex dynamic data.
Each verification method has pros and cons, and there is no one-size-fits-all option. You need to choose the solution that best fits your testing project.
Here's a sneak peek of how Katalon works:
Check out the feature comparison between Katalon and SoapUI made by G2 - the world's leading tech review website:
Download Katalon and Witness its Power in Action
API testing requires both positive and negative tests to ensure that the API is working correctly. Since API testing is considered a type of black-box testing, both types of testings are driven by input and output data. There are a few suggestions for test scenario generation:
Read More: Top 100+ Test Cases For The Login Page & Top 100+ Test Cases For eCommerce Websites
Scheduling API test execution every day while the testing process is live is highly recommended. Since API test execution is fast, stable, and small enough, it is easy to add more tests into the current testing process with minimum risks. This is only possible with automated API testing tools that come with features like:
Once the testing process is completed, you can get the result of those tests every day. If failed tests occur, you can check the outputs and validate issues to have proper solutions.
Read More: What is Live Testing? A Complete Guide
API testing flow is quite simple with three main steps:
The most touch parts of API testing are not either sending requests or receiving the response. They are test data management and verification. It is common that testing a few first APIs such as login, query some resources, etc. is quite simple.
The testing task becomes more and more difficult to further APIs. Therefore, the API testing task is easy to be underestimated.
At some point in time, you would find yourself in the middle of choosing a good approach for test data and verification methods. It is because the returned data have similar structures, but not the same in a testing project.
Furthermore, deciding the right one would be difficult if you should verify the JSON/XML data key by key, or use object mapping to leverage the power of programming language.
Considering API automation testing a real development project is highly suggested. It should be structured to be extendable, reusable, and maintainable.
There you have it: 10 API Testing Tips for you to set foot in the wonders of API Testing, no sweat.
Whether experienced or just starting out with API Testing, Katalon Studio is an optimal solution regardless of the level of expertise. Equipped with minimum maintenance requirements, integrations with CI/CD and DevOps practices and so much more.
There are reasons why Katalon is widely acclaimed by the testing community and on G2:
Learn how to better optimize your API tests with Katalon and LambdaTest with Katalon Academy here