What is an API?

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 datam

·         Status (say Pass or Fail)

·         Call to another API function.

The output is compared with the expected outcome. API test cases are written based on the input data that users are expected to key-in.

For example -

There is an API function which should add two integer numbers .

?

1

Long add(int a, int b)

The numbers have to be given as input parameters. Output should be summation of two integer numbers . This output needs to be verified with expected outcome.

Calling needs to be done such as

?

1

add (1234, 5656)

Exceptions have to be handled if number is exceeding the integer limit.

Consider the below API function -

1.     Lock()

2.     Unlock()

3.     Delete()

They return any value such as True (in case of success) or false (In case of error) as an output .

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

http://cdn.guru99.com/images/API2.png

 

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:

http://cdn.guru99.com/images/API3.png

1.     Understanding the functionality of the API program and clearly define 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.

Difference between Unit and API Testing:

Following are the differences between unit testing and API testing

 

Unit Testing

API Testing

Performed by developers

Performed by testers

Separate functionality is tested

End to End functionality has been tested

Developer can access the source code

Testers usually cannot access the code

UI testing is also involved

Only API functions are tested

Only Basic functionalities are tested

All functional issues are tested

 

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

Conclusion:

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.