Reading:
API Testing: Approach & Challenges

API Testing: Approach & Challenges

Metamug

//: # ()

The term “API” stands for Application Programming Interface. It refers to an interface that allows software developers to interact with other programs. An API is often used by programmers to create applications that use another program’s functionality.

REST API Testing: Approach, Tools & Challenges

REST API Testing is testing of the software. REST API at the end of the day is a software & all kinds of software demand testing. Whenever we build & deliver a REST API, it is important that we test the API for security, stability, performance & technical functionality.

REST API testing is a herculean task given the complexity of the API nature & architecture. REST API Testing is manual & automated. You need to write down code to test the API & use a testing tool to drive the API. Depending on the need of the situation, different kinds of API testing approaches & toolscan be used to test the software.

Some approaches to REST API Testing are:

  1. Unit Testing : Testing per unit or testing each operation

  2. Integration : Testing the relationship between different software modules (API & other software)

  3. Functional Testing : Testing the nature of the REST API for the desired & defined functionality

  4. Load Testing : Testing how much volume REST API can handle – number of calls

  5. Reliability Testing : Testing for consistency of results & connections

  6. Security Testing : Testing the security parameters like access control, encryption methods & for rights management

  7. Penetration Testing : This is a second level audit test

A plethora of API Testing tools are available in the market.

Three Commonly used tools for REST API Testing are:

REST Assured

As the name suggests (pun intended), you can be REST assured if you decide to use this tool. It is an open-source library built in Java. It is used to test RESTful Web Services. It has a lot of in-built functions. This is a great tool for testers which don’t want to run manual tests. It accommodates major HTTP testing methods like POST, GET, PUT, DELETE.

You can look at the below example from the REST Assured website (https://rest-assured.io/)for a game of Housie/Lotto. The below code test if the HTTP server returns the desired information, 

Test if the HTTP server returns the JSON at “http://localhost:8080/housie/{id}”:

{

  "housie": {
     "housieId":5,
     "winning-numbers":[2,40,30,23,7,4,3],
     "winner":[
        {
           "winnerId":23,
           "numbers": [2,40,30,23,3,4]
        },
        {
           "winnerId":54,
           "numbers":[51,3,12,10,18,22]
        }
     ]
  }
}

You can use REST Assured as a REST API Testing Tool to validate interesting things from the response:

@Test 
public void housie_resource_returns_200_with_expected_id_and_winner() {

   when().get("/housie/{id}", 5).
   then().statusCode(200).
          body("housie.housieId", equalTo(5),
              "housie.winner.winnerId", hasItems(23, 54));

}

Resty

This a command like tool meant for REST API testing. It works along with cURl, another command-line URL which isLinux based.You can visit below link on Github & refer to Chapter 7 of O’Reillys book for more details

https://beders.github.io/Resty/Resty/Overview.html

Postman

Postman is the best & popular REST API testing tool because it is highly compatible, highly supportive & very easy to use. It has testing tools for every stage in the REST API Lifecycle from design to production. It comes with a browser extension & can be used on MAC, Linux & Windows. You can check out the features on the https://www.postman.com/. It is a generic API testing tool & the application is not limited to REST API.

I personally prefer, insomnia over postman

REST API Testing challenges

Like every other thing in the universe, REST API Testing brings along with it some challenges: Some common challenges are:

  1. REST API Parameter Combination & Error : Different Rest API Parameters make different combinations which lead to multiple program states & errors. Some parameters which demand testing are request method, request URI & query parameter.

  2. Validation of REST API Parameters: Unvalidated String & Data Types lead to wrong string & data types. They have to validated to prevent errors.

  3. Data Format Schema Maintenance : The Data Formatting Schema has to be maintained to handle responses & requests. The schema has to be updated with new parameters from time to time.

  4. API calls order sequence : REST API calls are multi-threaded. The API calls have to be made in a certain order.

  5. Large volume of manual testing : Manual Testing can be exhausting especially if the project is very large. Setting automatic process for API Testing to reduce load & efficiency becomes a necessity.


Icon For Arrow-up
Comments

Post a comment