Testing

February 6, 2019

API Testing Tutorial – Quick Guide on the Basics

API Testing is critical for the software systems to perform at high-quality. This post covers the basics of API Testing, its types, the testing approach, best practices and tool used for this testing.

API act as the middle layer between the presentation and database layer in the software development process,. They enable communication and data exchange from one software system to another software system.

API testing is the most challenging aspect of QA testing, as APIs can be complicated. This testing involves protocols and standards that are are not involved in any other kind of testing.

The developers usually test the basic functionality while testers perform QA of functionality, performance, and security of APIs. Testers ensure that all components work together.

What is API Testing?

To understand API Testing, we need to first understand what is API?

So what is an API?

API stands for Application Programming Interface which is a set of routines, protocols, and tools that connects an application to the web or to other APIs.

A routine, also known as a procedure, function or subroutine, is a program that performs a particular task. A protocol is a format for transmitting data between two systems.

An API indicates how one software program should interact with another software program. API acts as an interface between two software applications by allowing them to communicate with each other.

API testing like any other testing tries to uncover bugs related to inconsistencies or deviations from the expected behavior.

Continuous testing is also very important to ensure that everything continues to work exactly as it should. The risk of releasing a bad and potentially insecure product in the market is greater has its repercussions.

APIs are involved in each and every system that we use. API testing is critical to ensure that our digital life runs in an increasingly seamless and efficient manner.

APIs make our phones “smart”, and they help to streamline a business process. If an API doesn’t perform efficiently and effectively, it will never be included in a software system. An error at the API level can break the flow of the entire application as a chain of integrated business processes will be disrupted.

Here are some common reasons why you should test your APIs:

  1. It is to ensure the API does what it’s supposed to do.
  2. It is to ensure that the API can handle the load.
  3. It will help to detect the ways the users can mess things up.
  4. To ensure that the APIs work across devices, browsers, and operating systems.
  5. With API testing there could be costs involved due to system failure.

What do you need To Start API Testing?

First of all, you need to set up a testing environment for API testing that includes the required set of parameters around the API.

This requires database and server configuration as per the application’s requirements.

As you are done setting up an API testing environment, make an API call to ensure nothing is broken before you go forward to start thorough testing.

You can start by combining your application data with your API tests. This helps to ensure that the API performs as expected against possible known input configurations.

At the next level, you should organize the API tests. You need to find answers to below questions:

  • Who is your target audience?
  • Who is the API user?
  • Which environment(s) should the API typically be used?
  • Which aspects are you testing?
  • Which problems are we testing for?
  • What are your priorities for testing?
  • What is supposed to happen under normal circumstances?
  • What could potentially happen under abnormal circumstances?
  • What are the criteria for Pass or a Fail? What data is the desired output? What is the chain of events?
  • Which other APIs could this API interact with?
  • Who on your team is in charge of testing what?

How to perform API Testing?

API testing is a form of integration testing that is performed to test the API to validate its functionality, reliability, performance, and security of the application for which API is used.

In this testing, the APIs and the integrations they enable are tested.

This testing is usually performed for software systems that have multiple APIs.

API Testing Tutorial

API testing should cover the following testing methods apart from usual SDLC process:

  • Discovery testing: The test group should manually execute the set of calls documented in the API. This could include something like verifying that a specific resource exposed by the API can be listed, created, and deleted as appropriate.
  • Usability testing: This testing verifies whether the API is user-friendly or not. Does the API integrate well with another platform as well?
  • Security testing: This testing includes the type of authentication that is required and ensures that the sensitive data is encrypted over HTTP.
  • Automated testing: API testing should enable the creation of a set of scripts or a tool that can be used to execute the API regularly.
  • Documentation: The test team takes care of the documentation to ensure it is adequate and provides enough information to interact with the API. Documentation should be a part of the final deliverable.

What are the benefits of API Testing?

Here are the benefits of this testing:

Provision to test early

In API testing, you don’t need to wait till other teams develop the whole application, the testing can be started in isolation once the logic is designed, tests can be built to validate the correctness in responses and data.

Provision for easy test maintenance 

API changes are less frequent – often API definitions files like OpenAPI Spec can help make refactoring tests that only take few seconds. In normal testing when UIs are constantly changing to cater to different – browsers, devices, screen orientation, etc., the tests needed to be updated constantly to keep up with the actual code in production.

Lesser time for resolution 

As and when API tests fail, we know exactly where the defect can be found in the system. This reduces the time required to track bugs between builds, integrations, and even different team-members. The small, isolated footprint of an API test is perfect for faster MTTR stats, a valuable KPI for DevOps teams.

Speed and Coverage of Testing

If we have 400 UI tests then they may take around 40 hours to run whereas 400 API tests could be run in 3 minutes. That implicates that you’ll find more bugs in less time, while also being about to fix them immediately.

An Example:

Let’s take the below example where there is a need to perform a common functional test at the UI level. The steps start with visiting the website, filling the form, then submit the form, and verify whether you are navigated to the next screen.

At the UI level, this simple test can fail at the browser and network connection level, having to load the browser each time we want to run an iteration of this test may fail.

Second, any of these elements doesn’t function, as it should such as the buttons are not clickable and you cannot select the options. You will have to verify thousands of combinations of inputs and scenarios.

With API Testing, this entire testing scenario can, and should, be boiled down to one step:

API Testing validates Application Programming Interfaces.

The main purpose of the API Testing is to check the functionality, reliability, performance, and security of the API (application programming interfaces). In this testing, we use software to send calls to the programming interface, get the output, and make a note of the system’s response. In any other testing, standard user inputs and outputs are usually tested.

API tests differ from GUI Tests as it doesn’t focus on the appearance and feel of the application but its focus is on the business logic layer of the software architecture.

What are the types of API Testing?

In this testing, the following types of testing are conducted:

Unit Testing: For testing the functionality of individual operation.

Functionality Testing: For testing the functionality of multiple unit tests when tested together.

Load Testing: For testing the functionality and performance under load conditions.

Error Detection: For identifying any errors such as exceptions and resource leaks.

Security Testing: For testing that the API is secure against any external threats.

UI Testing: For testing the functionality of user interface as part of end-to-end integration tests to ensure the UI functions as expected.

Interoperability & WS Compliance testing: This type of testing applies to SOAP APIs and it ensures conformance to Web Services (WS) Interoperability Profiles. The compliance is tested to ensure that the predefined standards are met.

Penetration Testing: For detecting any vulnerabilities of an application from attackers.

Fuzz Testing: For testing the API by giving inputs in an attempt to crash it.

API Testing Approach

Quality Assurance team performs API testing which is a form of Black Box Testing. This testing is conducted post the build is ready.  The source code is not included in the this testing.

In this testing, a request is sent to the API with known to analyze the response that includes:

  • Accuracy of data
  • HTTP status code
  • Response time
  • Error codes of any errors returned by API
  • Authorization checks
  • Results of non-functional tests such as performance, security, etc.

What are the types of Bugs & Defects that API testing detects?

API testing detects many different types of bugs which could make product experience bad. Here is a list of some common defects which API testing can detect easily:

Types of bugs found in API testing

Following are the types of bugs found:

  • Duplicate or missing functionality
  • Improper messaging
  • Error handling mechanism is incompatible
  • Multi-threaded issues
  • Security, performance & security issues
  • Reliability issues

API Testing Guidelines-Best practices

  • Test the API to check what happens consistently and what doesn’t.
  • Perform stress testing on the system through a series of API load tests.
  • Test the API for failures; until you get the output as failed. Test the API so that it fails consistently.
  • Group the test cases by test category.
  • Mention the parameters selected in the test case itself.
  • Prioritize API function calls to simplify testing for testers so that they can finish testing on time.
  • Automate the API documentation creation process and ensure a good level of documentation is there which is easy to understand.
  • Plan to perform call sequencing.
  • Create test cases for all possible API input combinations to get complete test coverage.
  • Reuse test cases and monitor the API in production.
  • Depend on manual and automated tests for better API testing outcomes.

API Testing Tool

For successfully performing API Testing, you require a tool to structure and manage your test cases. You will also require full traceability of requirements and effective API documentation.

ReQtest is a test management tool that helps in API testing by allowing you to structure & categorize your test cases. You will also get full requirements traceability with a high-level of API documentation. You can sign-up for a free ReQtest trial.

Challenges of API Testing

Just like other software testing techniques, API testing also has some challenges. Some of the common API testing challenges are given below:

  • The main challenge in Web API testing is Parameter Combination, Parameter Selection, and Call Sequencing
  • There is no GUI available to test the application that makes it difficult to give inputs.
  • To validate and verify the output in a different system is difficult for testers.
  • The testers must be aware of parameter selection and categorization.
  • Exception handling function should be tested
  • Coding knowledge is necessary for testers

Summary

API Testing is an integral part of the software quality assurance process. You need the right approach and tool to improve your testing outcomes. The more your testing process is structured; the better will be the outcomes of the testing.

Share article