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 API Testing is 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. UFT is 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 don't support.
Type of API test support by HP UFT
- Web service
- Object-Oriented Language
- Proprietary API
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 profile of specified user on Facebook.
- Verify that profile is as per expectation
Here is 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 HTTP Request to make a request to Facebook API.
Step 3: Configure and passing parameters into HTTP request
- Right click on Object HTTP Request to edit this object.
- In Properties part, Enter URL
https://graph.facebook.com/v2.3/me?access_token=CAACEdEose0cBANJsDnbZC92mNA ghaM6xxZCZBZAvKlMXS98VYvKyOlrfAdsUWR8x5aw9Kqc0grscs9zb9IYED4VC3FwapIZBj%20dsuxyHdLcff38gYUBFNeRQ lH%20fN7eXKoVZBNl0bR233ZAZCw8fLF1QLh98ry2ZBeYBhXLabtTDkFPZA1IqhaMG0mQp30zO1QxQ19nVCxZArJA6XR oB1o5FMepII5cn3DgbBmTgZD
Also you can passing 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
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. Incase status code is 200 that mean 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 test case is failed, test results like following figure.
Incase test case is passed, we have report as below
Ok, now we 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 testing in software development process because it has many advantages
- API is trend of the testing
- Time effective
- Language independent
- Easy GUI integration
There're many tool to perform the API testing, QTP is one of the best tool to do this test. Although QTP has some disadvantages, but QTP is still a very powerful tool for API testing with its benefits