API Testing Explained: Types of API Testing for Dummies

SweetCodey
5 min readMay 23, 2024

--

Smoke Testing

The purpose of smoke testing is to quickly check if the main functions of the API are working without going into detailed testing. It’s like a quick check to see if the system is ready for more rigorous testing.

Example: A common practice for this is doing a simple health check. We send a request to /api/health-check to ensure it returns a 200 OK status. If not, our smoke test fails.

Health Check

Functional Testing

As the name suggests, the purpose of functional testing is to verify that all the main functionalities of our API work as expected.

Example: Let’s consider a very simple API that manages a To-do list. The API has endpoints to add, retrieve, update, and delete tasks. The below diagram illustrates what the requests are and what should be the expected responses. So, functional testing basically checks that the response we get from our system is same as the expected response.

Integration Testing

The system that we have built might have multiple endpoints or there could be multiple services talking to each other internally. In integration testing, we check if the integration between those services is working as expected. We would be sending such a request to the service which involves interactions between multiple components or services.

Example: Let’s continue with our To-do list application where the API interacts with a database service. We will test the integration of these components by adding a task and ensuring it gets stored in the database.

Regression Testing

Now, let’s come on to Regression testing. It is a way in which we confirm that recent code changes (like new features or bug fixes) have not broken existing functionalities. It’s about making sure everything that used to work still works as expected.

Example: Let’s continue with our To-do list application. We have introduced a new feature where users can assign priorities to their tasks. So, in regression testing we test all the previously existing features (like adding, deleting, updating tasks) and then verify that all of them work as expected.

Load Testing

This type of testing just checks how much load your system can handle. So, we will be sending lots and lots of API requests and measure how much traffic can your system handle. Through this, we assess how the API performs under expected, normal load conditions.

Example: Let’s say we want to load test our To-do application’s GET tasks endpoint. So, we will send 1000 concurrent GET requests to /api/tasks and then verify that most responses should return within an acceptable time frame (e.g., under 1 second).

Stress Testing

In this, we test the API’s behavior under extreme conditions (beyond the expected traffic), to see how it handles stress and identify its breaking point. Unlike load testing, which checks performance under expected loads, stress testing pushes the system beyond its normal operational capacity to see how it recovers from failure.

Example: In our To-do app let’s say we do stress testing on GET tasks endpoint. So, we gradually increase the number of concurrent requests to retrieve tasks until the API fails (failing means server sends 500 Internal Server Error or times out). We then note the breaking point and also observe how the system recovers after failure (e.g., does it return to normal operation when the load decreases?).

Security Testing

This identifies vulnerabilities and ensures the API is protected against threats like hacking, unauthorized access, and data breaches. We will try to break the security of our system like sending thousands of requests by one user or try accessing someone else’s data. And then see if we are getting expected errors and response codes.

Example: For our To-do application, we will test for common security issues such as unauthorized access and DoS (Denial of Service) attacks.

UI Testing

In this type of testing we verify that the user interface (UI) interacts correctly with the API. This ensures that data flows correctly between the UI and the API and that the UI displays the correct information.

Example: In our To-do app, we can test the interaction between the UI and the API to ensure tasks can be added and displayed correctly. We can enter “Buy groceries” in the task input field and click the “Add Task” button. Then we can verify that the API request was a POST request to /api/tasks with { "task": "Buy groceries" } and that the new task “Buy groceries” appears on the task list.

Fuzz Testing

Fuzz testing is all about testing your API’s robustness by sending random or invalid data to see if it can handle errors gracefully. This helps in identifying vulnerabilities and unexpected behavior.

Example: For our To-do application, we can fuzz test by sending a POST request to /api/tasks with invalid data such as {"task": ""} . If our response is {"error": "Task cannot be empty"} with a 400 Bad Request status, then our fuzz test passed.

References

--

--

SweetCodey

🚀 Team of SDEs in Amazon & Microsoft trying to make every developer's life easier