API and API Testing




API definition and API Testing


Application Programming Interface(API) is defined as a collection of software procedure and functions. This API can be used by other software..


What is API Testing?

API testing is highly used for testing those systems which contains collection of API. For example that system may be Application software, system software or libraries. This testing is very different from GUI based testing. In spite of GUI testing does not come under API testing but even though we need to set up initial

phase environment and also we need to call API with set of parameters and then analyzing the output. There is some complexity in setting up initial environment due to absence of GUI. For API testing you have to be sure that all are set up and systems are ready to be tested. Later it is divided in Application setup and test

environment. setting up the environment involve some work like database configuration, server running and regarding test environment. on another side make sure that object is properly initialized before calling their non static members of that class and it comes under application setup. Under initial setup also we need to create some conditions under which API will is called. Perhaps API is called directly or it should be called in responded of some exception.


Test Cases Involved in API Testing:

Test cased are generated based on output.


1)based on Return value of input condition

This test is based on input we give and we validate the output on the basis of input. Writing test case for some some king of API like int add(int a, int b) is very easy. You pass multiple combinations for a and b and validate the output.
2)Trigger some other API/event/interrupt
The result of API if fires some event or produce some interrupt, then they should be tracked. Test suite supposed to call related API and declarations is based on interrupts and listener

3)Does not return anything

We need to check the behavior of software of system if nothing is returned.
For example:- If we have to delete list element and then we require to validate absence of list element and its size in the list.


4)Update data structure

This category is related to that category which nothing returns, On update of data structure offcourse will effect system that need to be validated.


5)Modify certain resources

If API call effects some resources like changing registry, killing process, updating database then it should be validated.

API Testing vs. Unit Testing: What’s the difference?

1)API testing is different from unit testing and owned by QE team and development team. Unit testing known as white box testing and API testing is known as black box testing.

2)Similarity between these two is both target code-level so using same type of tool for both type of activity. There are several tools which are open source for API testing for example HttpUnit, Webinject, XMLUNIT, etc.


3)API test involves methods of 2EE APIs, JAVA, DOTNET etc and also test these API for Application servers.


4)development team owns the unit testing and the developers are supposed to create unit test for each code module for example stored procedures, functions, classes, etc and also confirm that these module pass its own unit test before code is build. On the other and API testing are owned by QE team and its staff. API test is normally run after build is confirmed to be ready and the common thing is authors of test is not given access to source code, they build black box testing in respect to API.

5)Another difference between these two testing type is test case design. Unit test is designed for verification of each unit under isolation behaves as it is supposed. If we talk about scope of these testing then unit testing does not consider system level functions of various units. while API test, specially designed for considering the whole functionality of the software system as it is going to be used by end user so API testing is more extensive in comparison to unit test and supposed to take sorts of scenarios which API will be used for and typically include transactions between many modules with in application.

API Testing Approach


An approach for testing Product which an API contains.

Step I) API testing required some coding and normally is beyond the scope of what developer is expected for doing. This activity should be owned by Testing team.


Step II) Some traditional testing is also applied to API testing like equivalence classes, boundary analysis etc. Thus whatever you are not good in coding but still you can design API test.

Step III) As we know it is impossible to test whole scenarios so mostly focus on important scenarios and apply some techniques for example soap opera testing and also try forced error testing by using multiple data types and different size. Challenge of API testing is divided in to below given categories


a)Call sequencing
b)Parameter combination

c)Parameter Selection


API Framework


This framework is self-explanatory. Config file is used for holding the configurable parts and there values for test run. Automated test cases must represent in "parse - table" format within config file. This script must be effectively configurable. When API testing, it is not essential to test each API so the config file have some

sections whose all API are made activated for that specific run. Test cases are picked up based on it. Although it is very tedious to include test case parameters in config file but it must be designed in this way that test case is left static with the facility to 'activate' and 'deactivate' them


Definitions:

Soap Opera Testing:


This test is exaggerated and made to complicate scenarios in such a way that television soap operas are made to exaggerate and to complicate real life


Forced Error Testing:

It is same as mutation testing. Its the way of inducing changes/errors for the application to explore how application is supposed to be working. FET (forced-error- test) contains negative cases which is designed to force a program unit into error condition. All the error messages should be generated by this program in the form a list. This list is very important and is baseline for development test cases.


Software Functions and Procedures:

Procedures and functions are the base of program. They facilitate the structure to build a program into small logical units which become easy to manage and it can manage various activities needed by program


Functions

There are basically two types of functions:

Built-in

this type function are already provided with the system and they are supposed to do some operations like printing, writing, opening and closing files, converting variables etc.

Application/user-specific

As per requirement of the program you can create procedures and functions by using built-in system procedures, functions and variables.


Procedures

Procedures are supposed to do series of tasks. Normally they combine other functions and procedures within a program. Main difference between procedure and function is procedure does not return value. It is executed and control come back to calling subroutine or procedures. In Visual Basic it is called "Subroutines" and "Sub" in short. "Function" is used like procedures in JavaScript it return null or no value to whatever they called by.

FOLLOWING ARE THE TIPS AND QUEST. / ANS. ON THE API AND API TESTING:


What is API and API Testing?

API:  Stands for Application Programming Interface.
An API actives the communication in between two different -2 software application system. Application implementing an API contains methods / sub-routines, which can be called by another application software. Then Finally API’s are functions which are used in one application and can be executed by another application.

API Testing: Testing the interface of application programming of any system software.  Simple requirement of API Testing is, API function need to call from the Calling application. It required database, server, application setup and all necessary test environment.

API test cases perform to check the functionality of the application related to business logic. This is totally different to GUI Testing. Test engineer doesn’t test the look and feel of application software in this testing.
API and API Testing
API and API Testing

Test Cases for API environment and set – up: Set up of API environment is complicated as there is not any interface to test. According to software requirement, database and server should be configured. Execution of API function is used to check whether that API is working or not.

API output can be:
i.                    Any type of record (data)
ii.                  Pass or Fail – Status
iii.                Call to another / next API function.

Output always compared with expected outcome. API test cases created on the base of input data.

Example: API function adding two numbers:-
i.                    Long add(int r, int s)

Here numbers will be provided as input and output should be submission of these provided two integers. And this output should match and verified with expected result.

i.e. add (6789, 1235)

Let’s check following API Functions-
i.                    Delete()
ii.                  Lock()
iii.                Unlock()

Above functions will return the values such as True (If pass) and False (If Failed) in output. These functions can be used anywhere and also can call from anywhere.

Calling to another API / Event: Here our application will call one API function and that API function will call another one function.
EXAMPLE: Delete function in database will call by our application then another one function REFRESH the database will be called automatically.

API Testing Approach:
i.                    API program functionality needs to understand so that clearly decided the scope of testing.
ii.                  Boundary value analysis, error guessing and equivalence classes techniques need to applied and creating the test cases for API.
iii.                Input data or record need to properly planned and defined correctly, Mean input value should be valid.
iv.                Now execute the test cases and check the output with expected output.

Difference Between API and Unit Testing:

Difference between Unit and API Testing
Difference between Unit and API Testing

Automation of API Testing:
Following automation tool can be used for API Testing-
i.                    NUnit for .Net
ii.                  JUnit for Java

Best Practices of API Testing:
i.                    Planning and organize the test cases properly and appropriately
ii.                  All parameters should be explained properly in the test case
iii.                Call sequencing and Prioritize API functions
iv.                Testing should be proper

API Testing Challenges:
i.                    GUI is not available to test any application
ii.                  Validating and Verifying the output
iii.                Parameters categorization and selection
iv.                Proper Exception Handling
v.                  Test Engineer should have knowledge of code







No comments:

Post a Comment

Popular Posts