Mobile App Development

What is an API?

API is an acronym for Application Programming Interface.

It enables communication and data exchange between two separate software systems. A software system implementing an API contains functions/subroutines which can be executed by another software system.

What is API Testing?

API Testing is entirely different from GUI Testing and mainly concentrates on the business logic layer of the software architecture. This testing won’t concentrate on the look and feel of an application.

Instead of using standard user inputs(keyboard) and outputs, in API Testing, you use software to send calls to the API, get output, and note down the system’s response.

API Testing requires an application to interact with API. In order to test an API, you will need to

  • Use Testing Tool to drive the API
  • Write your own code to test the API

Set-up of API Test environment

  • API Testing is different from other software testing types as GUI is not available, and yet you are required to set up an initial environment that invokes API with a required set of parameters and then finally examines the test result.
  • Hence, Setting up a testing environment for API testing seems a little complex.
  • Database and server should be configured as per the application requirements.
  • Once the installation is done, the API Function should be called to check whether that API is working.

Types of Output of an API

An output of API could be:

  1. Any type of data
  2. Status (say Pass or Fail)
  3. Call another API function.

Test Cases for API Testing:

Test cases of API testing are based on:

  • Return value based on input conditionit is relatively easy to test, as input can be defined and results can be authenticated.
  • Does not return anythingWhen there is no return value, the behavior of the API on the system to be checked.
  • Trigger some other API/event/interruptIf an output of an API triggers some event or interrupt, then those events and interrupt listeners should be tracked.
  • Update data structureUpdating data structure will have some outcome or effect on the system, and that should be authenticated
  • Modify certain resourcesIf API call modifies some resources then it should be validated by accessing respective resources.

Approach of API Testing

Following points helps the user to do API Testing approach:

  1. Understanding the functionality of the API program and clearly defining the scope of the program.
  2. Apply testing techniques such as equivalence classes, boundary value analysis, and error guessing and write test cases for the API.
  3. Input Parameters for the API need to be planned and defined appropriately.
  4. Execute the test cases and compare expected and actual results.

How to do API Testing

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

  • Discovery TestingThe test group should manually execute the set of calls documented in the API 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 functional and user-friendly. And does API integrate well with another platform as well.
  • Security TestingThis testing includes what type of authentication is required and whether sensitive data is encrypted over HTTP or both.
  • Automated TestingAPI testing should culminate in the creation of a set of scripts or a tool that can be used to execute the API regularly.
  • DocumentationThe test team has to make sure that the documentation is adequate and provides enough information to interact with the API. Documentation should be a part of the final deliverable

Best Practices of API Testing

  • Test cases should be grouped by test category.
  • On top of each test, you should include the declarations of the APIs being called.
  • Parameters selection should be explicitly mentioned in the test case itself.
  • Prioritize API function calls so that it will be easy for testers to test.
  • Each test case should be as self-contained and independent from dependencies as possible.
  • Avoid “test chaining” in your development.
  • Special care must be taken while handling one-time call functions like – Delete, CloseWindow, etc…
  • Call sequencing should be performed and well planned.
  • To ensure complete test coverage, create test cases for all possible input combinations of the API.

Types of Bugs that API testing detects

  • Fails to handle error conditions gracefully.
  • Unused flags
  • Missing or duplicate functionality.
  • Reliability Issues. Difficulty in connecting and getting a response from API.
  • Security Issues
  • Multi-threading issues.
  • Performance Issues. API response time is very high.
  • Improper errors/warning to a caller.
  • Incorrect handling of valid argument values.
  • Response Data is not structured correctly (JSON or XML).

Tools for API testing

Since API and Unit Testing both target source code, tools/frameworks can be used for their automation.

  • Parasoft SOAtest
  • Runscope
  • Postman
  • Curl
  • Cfix
  • Check
  • CTESK
  • dotTEST
  • Eclipse SDK tool- Automated API testing

Check out top API Testing Tools List

Challenges of API Testing

Challenges of API testing includes:

  • Main challenges in Web API testing are Parameter Combination, Parameter Selection, and Call Sequencing.
  • There is no GUI available to test the application which makes it difficult to give input values.
  • Validating and Verifying the output in a different system is little difficult for testers.
  • Parameters selection and categorization is required to be known to the testers.
  • Exception handling function needs to be tested
  • Coding knowledge is necessary for testers

Conclusion:

API consists of a set of classes/functions/procedures which represent the business logic layer. If the API is not tested properly, it may cause problems not only in the API application but also in the calling application. It is an indispensable test in software engineering.

Successive
Advantage

Successive Advantage

We design solutions that bring unmatchable customer experience to life and help companies accelerate their growth agendas with breakthrough innovation.

Connect with us ➔
pattern
pattern icon