• Home
  • Testing
  • SAP
  • Web
  • Must Learn!
  • Big Data
  • Live Projects
  • Blog

What is API Testing?

Before Testing API, we need to know about API. An API (Application Programming Interface) is a collection of software functions and procedures which can be executed by other software applications.

So API Testing is:

  • Testing without GUI
  • Programmatically simulate data or control follow scenarios.
  • Focus on functionality, not on behavior or customer experience.

API Testing with QTP

Why is API Testing important?

API Testing have four significant advantages

  1. 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.

API Testing with QTP

  1. 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.

  1. 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.

  1. 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

  1. Web service
  2. Rest
  3. Object-Oriented Language
  4. Database
  5. 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

  1. Get a profile of the specified user on Facebook.
  2. Verify that profile is as per expectation

Here is a step to build a test flow for this API.

API Testing with QTP

Step 1: Open HP UFT and create new project API Testing

  1. Choose Start > (All) Programs > HP Software > HP Unified Functional Testing > Unified Functional Testing.

    API Testing with QTP

 

  1. Click File > New > Test. Select the API Test type

    API Testing with QTP

  2. 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.

API Testing with QTP

Step 2: Adding HTTP Request to Test Flow.

We will use the HTTP Request to make a request to Facebook API.

  1. Select Toolbox > Network

    API Testing with QTP

  2. Drag element HTTP Request to Test Flow.

API Testing with QTP

Step 3: Configure and passing parameters into an HTTP request

  1. Right, click on Object HTTP Request to edit this object.

    API Testing with QTP

  2. In Properties part, Enter URL

    API Testing with QTP

    https://graph.facebook.com/v2.3/me?access_token=CAACEdEose0cBANJsDnbZC92mNAghaM6xxZCZBZAvKlMXS98VYvKy%20OlrfAdsUWR8x5aw9Kqc0grscs9zb9IYED4VC3FwapIZBj%20dsuxy%20HdLcff38gYUBFNeRQlH%20fN7eXKoVZBNl0bR233ZAZCw8fLF1QLh98ry2ZBeYBhXLabtTDkFPZA1IqhaMG0mQp30zO1%20QxQ19nVCxZArJA6XRoB1o5FMepII5cn3DgbBmTgZD

    Also, you can passing a parameter into to API by set values Request Header

    API Testing with QTP

    You can use Graph API Explore of Facebook to get values of access_token.

    API Testing with QTP

  3. Set HTTP method is GET method.
    1. Configure HTTP method

API Testing with QTP

  1. 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.

API Testing with QTP

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.

API Testing with QTP

Step4: View the result

The Run Results Viewer opens. In this example, if a test case is failed, test results like the following figure.

API Testing with QTP

In case test case is passed, we have reported as below

API Testing with QTP

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.

Summary

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

 

YOU MIGHT LIKE: