What is API Testing?
So API Testing is:
- Testing without GUI
- Programmatically simulate data or control follow scenarios.
- Focus on functionality, not on behavior or customer experience.
Why is API Testing important?
API Testing have four significant advantages
- API testing is the trend
As you see the following figure, Api Testing grown up very fast in the last 10 years. It becomes very popular testing compared to other testing.
- Time efficient.
With API Testing we can use parallel execution to reduce test execution time. You can save up to 5 times compared to other testing Types.
- Language independent
In API Testing, data is exchanged via XML or JSON so that any language can be used to test the response. For example, if you have service whose response is in JSON format, you can easily parse data with Java, C# or any language.
- Easy GUI integration.
API Testing with UFT (Unified Functional Testing)
There are many tools available both open-source and commercial. Micro Focus UFT is the best tool to execute API Test with simple UI and configuration.
The last version of QTP called HP Unified Functional Testing (UFT), is a combination of HP QTP (GUI testing tool) and HP Service Test (API testing tool). Also, QTP supports Web, Java, .Net, Oracle, Siebel, Web-services, and many other major language and platforms, which some older version doesn't support.
Type of API test support by HP UFT
Start your first API testing with QTP
In this tutorial, we are doing to test Graph API of Facebook. We will test API as Test Case below
Get a profile of the specified user on Facebook.
Verify that profile is as per expectation
Here is a step to build a test flow for this API.
Step 1: Open HP UFT and create new project API Testing
Choose Start > (All) Programs > HP Software > HP Unified Functional Testing > Unified Functional Testing.
Click File > New > Test. Select the API Test type
When a dialog box opens, input name of API test: API_Facebook. And select a location to save this project.
Click Create to create a project API Test.
Step 2: Adding HTTP Request to Test Flow.
We will use the HTTP Request to make a request to Facebook API.
Step 3: Configure and passing parameters into an HTTP request
Right, click on Object HTTP Request to edit this object.
In Properties part, Enter URL
Also, you can passing a parameter into to API by set values Request Header
You can use Graph API Explore of Facebook to get values of access_token.
Set HTTP method is GET method.
- Configure HTTP method
Configure Checkpoints of HTTP Request
A set Status code is "200" in Checkpoints part. Checkpoints allow you to see whether the action was successful without having to manually check the result. Checkpoints are the means to validate the test a success or failure is determined by its checkpoints. In case status code is 200 that means test case is passed.
Step3: Run the test
Click the Run button or press F5 to open Run Test dialog box. Click Run to compiler and run the test.
Step4: View the result
The Run Results Viewer opens. In this example, if a test case is failed, test results like the following figure.
In case test case is passed, we have reported as below
Ok, now we have done your first API testing using QTP
Where to go from here
Now that you have learned to create a test with API test in UTF, you can create your own test for your GUI-less application.
API testing is the testing below the GUI and programmatically simulates data or control follow scenarios.
API testing is one of the most popular testings in the software development process because it has many advantages
- API is a trend of the testing
- Time effective
- Language independent
- Easy GUI integration
There're many tools to perform the API testing, QTP is one of the best tools to do this test. Although QTP has some disadvantages, QTP is still a very powerful tool for API testing with its benefits