API Automation Testing Series Part 3: Types of APIs and How to Automate Them

Testrig Technologies
6 min readOct 31, 2023

Welcome back to the third installment of our API Automation Testing Series. In the previous parts, we explored the ‘Why’ and ‘How’ of API automation testing. We learned why API testing is crucial in modern software development and how to get started with automating these tests effectively.

In this third part, we’re taking our journey a step further, delving into the exciting world of APIs, specifically the different types of APIs, and understanding how to automate testing for each of them.

Types of APIs

APIs, or Application Programming Interfaces, come in various flavors, each serving different purposes and use cases. Let’s briefly explore the four main types of APIs:

RPC (Remote Procedure Call) APIs:

  • RPC APIs enable communication between programs running on different systems, just like a function call in a local program.
  • They’re commonly used for distributed applications and can be implemented using protocols like gRPC or SOAP.

REST (Representational State Transfer) APIs:

  • REST APIs are the most popular and widely used type of API.
  • They follow a set of architectural constraints, making them simple and efficient, using HTTP methods like GET, POST, PUT, DELETE, etc.
  • REST APIs are the foundation of the modern web and are commonly used in web services and mobile applications.

SOAP (Simple Object Access Protocol) APIs:

  • SOAP is a protocol for exchanging structured information using XML.
  • These APIs are known for their strict standards and strong security features, making them suitable for applications where data integrity and reliability are paramount.

GraphQL APIs:

  • GraphQL is a query language for APIs that allows clients to request exactly the data they need and nothing more.
  • Unlike REST, where the server defines the structure of responses, GraphQL clients dictate what they want to receive.
  • GraphQL is gaining popularity for its flexibility and efficiency in handling complex data fetching requirements.

How to Automate Different Types of APIs?

1. RPC API Automation:

  • Select a Programming Language: Choose a language supported by your RPC framework. For this example, let’s use Python.
  • Use the RPC Library: If your API uses a specific RPC framework, you’ll need to install and use it. For demonstration purposes, let’s use a simple Python module to simulate RPC.
  • Create Functions for API Calls: Define functions that make RPC calls. These functions should encapsulate the request, call the API, and handle the response.
  • Write Test Cases: Create test cases that invoke the functions, pass parameters, and validate responses.
  • Testing Framework: Use a testing framework like unittest in Python to structure and run your tests.
  • Data Setup and Teardown: Manage test data setup and cleanup as required for your RPC API.
  • Integration with CI/CD: Integrate your RPC API tests into your CI/CD pipeline for automated testing during development.

Example (Python — Simulated RPC):

Suppose we have a simple RPC API for a calculator service that provides add, subtract, multiply, and divide operations. We’ll use a Python module to simulate this API.

In this example, we have simulated a simple RPC service for a calculator. The test_calculator.py script contains test cases for different RPC calls. These test cases invoke functions from the CalculatorService class and validate the results.

2. REST API Automation:

  • Select a Programming Language: Choose a language, e.g., Python.
  • Use the Requests Library: For making HTTP requests, use the requests library in Python.
  • Write Test Cases: Define test cases that include API endpoints, HTTP methods, request data, and expected responses.
  • Testing Framework: Utilize a testing framework like unittest or pytest to structure and run tests.
  • Send Requests: Use the requests library to send HTTP requests within your test cases.
  • Validate Responses: Verify the response status code, content, and specific data elements.
  • Data Setup and Teardown: Manage test data setup and cleanup as needed.
  • Integration with CI/CD: Integrate REST API tests into your CI/CD pipeline for automated testing.

Let’s automate testing a simple RESTful task management API:

API Endpoints:

  • GET /tasks — Retrieve all tasks.
  • POST /tasks — Create a new task.
  • PUT /tasks/{id} — Update a task by ID.
  • PATCH: Partially update a task by ID
  • DELETE /tasks/{id} — Delete a task by ID.

In this example, we use the requests library to send HTTP requests to a REST API. The test cases validate the response status codes.

3. SOAP API Automation:

Step-by-Step Approach:

  • Select a Programming Language: Choose a language compatible with SOAP testing, e.g., Python.
  • Use SOAP Libraries: For SOAP APIs, you may use libraries like SUDS (Python) to interact with SOAP services.
  • Write Test Cases: Define test cases that include SOAP requests and expected responses.
  • Testing Framework: Utilize a testing framework like unittest to structure and run your SOAP API tests.
  • Send SOAP Requests: Use SOAP libraries like SUDS to send SOAP requests within your test cases.
  • Validate SOAP Responses: Verify SOAP responses by checking the XML content and response status.
  • Data Setup and Teardown: Manage test data setup and cleanup as needed.
  • Integration with CI/CD: Integrate SOAP API tests into your CI/CD pipeline for automated testing.

Example (Python — SOAP API):

Let’s automate testing a simple SOAP API for a weather service.

API Endpoint: POST /weather

In this example, we use the SUDS library for Python to send SOAP requests. The test_get_weather test case sends a SOAP request to get weather information for New York and validates the response.

4. GraphQL API Automation:

  • Select a Programming Language: Choose a language that supports sending HTTP requests, e.g., Python or JavaScript.
  • Use Libraries: Use libraries like requests (Python) or axios (JavaScript) to make HTTP requests to the GraphQL endpoint.
  • Write Test Cases: Define test cases that include GraphQL queries and expected JSON responses.
  • Testing Framework: Use testing frameworks like unittest (Python) or Jest (JavaScript) to structure and run your GraphQL API tests.
  • Send GraphQL Queries: Use the selected library to send GraphQL queries within your test cases.
  • Validate GraphQL Responses: Verify GraphQL responses by checking the JSON content and specific data elements.
  • Data Setup and Teardown: Manage test data setup and cleanup as needed.
  • Integration with CI/CD: Integrate GraphQL API tests into your CI/CD pipeline for automated testing.

Example (Python — GraphQL API):

Let’s automate testing a simple GraphQL API for a fictional movie database.

In this example, we use the requests library in Python to send a GraphQL query to the movie database API. The test case validates the response status code and the presence of specific data elements in the response.

Conclusion:

API automation testing is a crucial aspect of ensuring the quality and reliability of your applications in today’s software development landscape.

Stay tuned for the next part of our series, where we’ll dive even deeper into the best practices for effective API testing.

Testrig’s API Automation Testing strategy empowers organizations to enhance their release velocity, expedite time to market, and significantly reduce overall testing efforts. The outcome is a substantial return on investment (ROI).

To delve deeper into the benefits of API Test Automation, we encourage you to review our informative case studies. https://www.testrigtechnologies.com/case-study/

Connect with Testrig, a leading API Testing Company, and embark on your API testing journey today!

--

--

Testrig Technologies

As an independent software testing company, we provide modern quality assurance and software testing services to global clients.