API is an acronym for Application Programming Interface.
It enables communication between two separate software system. A software system implementing an API contains functions/sub-routines which can be executed by another software system.
What is API Testing?
API testing is checking Application Programming Interface of a Software System.
In order to check API , it needs to be called from the calling software . Necessary test environment, database, server, application setup needs to be prepared before doing API Testing.
API testing is focused on the functionality of the software’s business logic and it is entirely different from GUI testing. It mainly concentrates on the business logic layer of the software architecture. This testing won’t concentrate on the look and feel of an application.
Set-up of API environment and different types of test cases:
Normally, setting up the API environment is very complex as it doesn’t involve user interface. Database and server should be configured as per the application requirements. API Function should be called to check whether that API is working.
Output of API could be
- Any type of data
Status (say Pass or Fail)
Call to another API function.
For example –
There is an API function which should add two integer numbers .
Code: Select all
1.Long add(int a, int b)
Calling needs to be done such as
Code: Select all
1.add (1234, 5656)
Exceptions have to be handled if number is exceeding the integer limit.
Consider the below API function -
A more accurate test case would be , can call the functions in any of the script and later check for changes either in the database or the Application GUI.
Calling of another API / Event
In this case , we call one of the API function which in turn will call another function.
For example – First API function can be used for deleting a specified record in the table and this function in turn call another function to REFRESH the database.
Approach of API Testing:
Following points helps the user to do API Testing approach:
- Understanding the functionality of the API program and clearly define the scope of the program
Apply testing techniques such as equivalence classes, boundary value analysis and error guessing and write test cases for the API
Input Parameters for the API need to be planned and defined appropriately
Execute the test cases and compare expected and actual results.
Difference between Unit and API Testing:
Following are the differences between unit testing and API testing
API Test Automation:
Since API and unit testing both target source code, similar tools can be used for testing both.
If an API method is using .NET code, then the tool which is supporting should have .NET
Example for Automation tools are
- NUnit for .Net
JUnit for Java
Best Practices of API Testing:
There are some best practices for effective API testing:
- Planning the test cases – What and How to test the API functions
Important to organize the test properly so that those API can be organized properly
Parameters selection should be explicitly mentioned in the test case itself
Call sequencing should be performed and well planned
Prioritize API function calls so that it will be easy for testers to test
Proper testing and test cases should be done while handling one time call functions like – Delete, CloseWindow, etc….
Challenges of API testing:
There are various challenges when we are doing API testing:
- No GUI available to test the application which is difficult to give input values
Verifying and validating the output in different system is little difficult for testers
Parameters selection and categorization needs to be known to the testers
Exception handling function needs to utilized and used properly
Testers should be knowledgeable in coding
API consists of set of classes / functions / procedures which represent the business logic layer. If API is not tested properly, it may cause problems not only the API application but also in the calling application.
Read more at http://www.guru99.com/api-testing.html# ... cOb8UsD.99