The Goals of API Testing

Design and Build Great Web APIs — by Mike Amundsen (69 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 9 Testing APIs | TOC | Testing with SRTs 👉

First and foremost, the goal of API testing is to do just that — test the interface. That means you need to test each URL (or “endpoint”) in the API, including any possible input parameters. You also need to confirm the responses to those endpoint requests. For starters, you need to make sure each promised endpoint exists and accepts the inputs and produces the outputs expected. But that’s just a start.

Test the API’s Behavior

In addition to testing the interface, you also need to make sure the API behaves the way you’d expect from reading the Application-Level Profile Semantics (ALPS) description and the OpenAPI Specification (OAS) documents. For example, an API might have a rule that each request for a credit rating will return a value between 1 and 10. If the API returns a value of 0 or 13, that’s unexpected behavior.

Another API might have a rule that you can’t create two records with the same companyName value. That means any attempt to break that rule results in an API behavior of refusing to write the duplicate record and returning an HTTP 400 Bad Request response.

Finally, you might have an API that supports an HTTP request to approve a purchase order, as shown in the curl example that follows:

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.