Sei sulla pagina 1di 7

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 softwares business logic and it is entirely different from GUI testing. It mainly concentrates on the business logic layer of the software architecture. This testing wont 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 doesnt 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. 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

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:

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 Performed by developers Separate functionality is tested Developer can access the source code UI testing is also involved Only Basic functionalities are tested API Testing Performed by testers End to End functionality has been tested Testers usually cannot access the code Only API functions 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, Close Window, 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.

API TestingWhat is API? An API (Application Programming Interface) is a collection of software functions and procedures,called API calls, that can be executed by other software applications. What is API Testing? API testing is mostly used for the system which has collection of API that needs to be tested. Thesystem could be system software, application software or libraries.API testing is different from other testing types as GUI is rarely involved in API Testing. Even if GUIis not involved in API testing, you still need to setup initial environment, invoke API with requiredset of parameters and then finally analyze the result.Setting initial environment become complex because GUI is not involved. In case of API, you needto have some way to make sure that system is ready for testing.This can be divided further in test environment setup and application setup. Things like databaseshould be configured, server should be started are related to test environment setup. On the otherhand object should be created before calling non static member of the class falls under applicationspecific setup.Initial condition in API testing also involves creating conditions under which API will be called.Probably, API can be called directly or it can be called because of some event or in response of some exception. Test Cases for API Testing: The test cases on API testing are based on the output. Return value based on input condition Relatively simple to test as input can be defined and results can be validated.Example: It is very easy to write test cases for int add(int a, int b) kind of API. You can passdifferent combinations of int a and int b and can validate these against known results.

Does not return anything

Behavior of API on the system to be checked when there is no return value. Example: A test case to delete(ListElement) function will probably require to validate size of the list or absence of list element in the list. Trigger some other API/event/interrupt

The output of an API if triggers some event or raises some interrupt, then thoseevents and interrupt listeners should be tracked. The test suite should callappropriate API and declarations should be on the interrupts and listener. Update data structure

This category is also similar to the API category which does not return anything.Updating data structure will have some effect on the system and that should bevalidated. Modify certain resources

If API call is modifies some resources, for example makes update on some database,changes registry, kills some processes etc, then it should be validated by accessingthe respective resources.

API Testing vs. Unit Testing: Whats the difference? 1. API testing is not Unit testing. Unit testing is owned by development team and API by QE team.API is mostly black box testing where as unit testing is essentially white box testing.2. Both API-testing and unit-testing target the

code-level , hence similar tools can be used for bothactivities. There are several open source tools available for API testing and a few of them areWebinject, Junit, XMLUNIT, HttpUnit, ANT etc.3. API testing process involves testing the methods of .NET, JAVA, J2EE APIs for any valid, invalid,and inappropriate inputs, and also testing the APIs on Application servers.4. Unit testing activity is owned by the development team; and the developers are expected tobuild Unit tests for each of their code modules (these are typically classes, functions, storedprocedures, or some other atomic unit of code), and to ensure that each module passes its unittests before the code is included in a build. API testing, on the other hand, is owned by the QEteam, a staff other than the author of the code. API tests are often run after the build is ready, andit is common that the authors of the tests do not have access to the source code; they essentiallycreate black box tests against an API rather than the traditional GUI.5. Another key difference between API and Unit testing lies in the Test Case design. Unit tests aretypically designed to verify that each unit in isolation performs as it should. The scope of unittesting often does not consider the systemlevel interactions of the various units. Whereas, APItesting, are designed to consider the full functionality of the system, as it will be used by the enduser. This means that API tests must be far more extensive than unit tests, and take intoconsider ation the sorts of scenarios that the API will be used for, which typically involveinteractions between several different modules within the application. API Testing Approach An approach to test the Product that contains an API. Step I: Understand that API Testing is a testing activity that requires some coding and is usuallybeyond the scope of what developers are expected to do. Testing team should own this activity. Step II: Traditional testing techniques such as equivalence classes and boundary analysis are alsoapplicable to API Testing, so even if you are not too comfortable with coding, you can still designgood API tests. Step III: It is almost impossible to test all possible scenarios that are possible to use with yourAPI. Hence, focus on the most likely scenarios, and also apply techniques like Soap Opera Testingand Forced Error Testing using different data types and size to maximize the test coverage.Main Challenges of API Testing can be divided into following categories. Parameter Selection

Parameter combination Call sequencing API Framework The framework is more or less self-explanatory. The purpose of the config file is to hold all theconfigurable components and their values for a particular test run. As a follow through, theautomated test cases should be represented in a parse-able format in the config file. The scriptshould be highly configurable. In the case of API Testing , it is not necessary to test every API in every test run ( the number of APIs that are tested will lessen as testing progresses). Hence the config file should have sectionswhich detail which all APIs are activated for the particular run. Based on this, the test casesshould be picked up.

Since inserting the automation test case parameters into config file can be a tedious activity, itshould be designed in such a way that the test case can be left static with a mechanism of activating and deactivating them. Definitions: Soap Opera Testing: Soap opera tests exaggerate and complicate scenarios in the way that television soap operas exaggerate and complicate real life. Forced Error Testing: Forced error testing is nothing but mutation testing. It is process of inducing error /changes to the application to find how application is working. The forced-error test (FET) consists of negativetest cases that are designed to force a program into error conditions. A list of all error messages that theprogram issues should be generated. The list is used as a baseline for developing test cases. Software Functions and Procedures: Functions and procedures are the foundations of programming. Theyprovide the structure to organize the program into logical units that can manage the various activities neededfor a program. Functions There are two basic types of functions: Built-in

these are built into the programming environment and do things such as opening and closing files,printing, writing, and converting variables (e.g., text to numbers, singles to integers, etc.). Application/user-specific depending on what the program needs, you can build functions and proceduresusing built-in functions and procedures and variables. Procedures Procedures are used to perform a series of tasks. They usually include other procedures and functions withinthe program.Procedures typically do not return a value, they are simply executed and return control to the callingprocedure or subroutine.Procedures in Visual Basic are called "Subroutines," often "Sub" for short. In JavaScript, "Functions" are usedas procedures (they simply return no or null values to whatever called them).

Potrebbero piacerti anche