In API Testing, we think we’re trying to answer a simple question: Does the API work?

Let’s look at this API call. It creates a user with the details.

API Testing: A POST Request

Let’s say it returned 200 (OK). Yes, we all wanted a 201 (CREATED), but you get what you pay for. Since I didn’t pay, I also don’t get a response, just the status code.

Did it work? Yes it returned a succes status code, but do we trust the answer? Can I get to that user data that it claimed to save? Not with that empty response.
Ok, let’s change the response to include an ID. Like this.

API Testing: A response with just an ID

Looks better. Can I say it works now? I’ve got a bit more confidence, but I feel it needs to try harder.

More Reflection, Please

How about, if the response to my API call, the response included the data I sent?

It’s starting to look better. With the last two responses, I feel more confident about the “create user” API. The API response has shown me, that it has indeed listened to me.

But did it work? I don’t trust it yet. Let’s look for more proof.

If I can get to the user’s data back, and if I had a GET API, and I used the ID I got back, and if the right data is returned, I’d be more at ease.

API Testing: A GetById Response with theh created user data.

I also expect it to appear in the “all users” list, so if I had an API to request that list, I expect to see the details there.

API Testing: A Get All Users Request containing the created data

And to lower my anxiety even more, I want to be able to Delete the user that I created, successfully. If it’s there.

API Testing: A Delete Request - succesful for existing user.

And then, after deleting it for the first time, if I try to delete it again, I expect an error. Something like this:

API Testing: A Delete Request - failure for missing user.

API Testing Is not about testing APIs

Let’s get back to the question: How do you I if the API works?

Well, this is not the question we actually want to answer. What we’re really after, is feature behavior, not a specific API behavior. And features, in the API world, are really spread around multiple endpoints.

In order to check if features work, (or even work-work), we need the APIs to respond with enough information, that we can collect and boost our confidence that the features work. The more proof, the better.

To learn more about API testing – I have workshops for that. For developers. And testers.

Categories: Uncategorized

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *