chapter four

4 Testing API Designs

 

This chapter covers

  • Using question techniques to test designs and ideas
  • How to get teams collaborating around API designs to help facilitate testing
  • Documenting APIs to increase shared understanding and assist in testing
  • How testing API designs sits in a testing strategy

Imagine that someone is assessing our API sandbox, RBP, to determine if it’s an application that they would like to use for a B&B. As they begin to explore RBP, they discover that the Room API needs to be called to create a room that can be booked. As they look through the API documentation, they come across details similar to the ones in Figure 4.1:

Figure 4.1: Example API documentation

Based on this information we build and send the following HTTP request to see how the API responds:

POST /room/ HTTP/1.1
Host: automationintesting.online
Accept: application/json
Cookie: token=r76BXGVy8rlASuZB
 
{
"roomNumber":100,
"type":"Single",
"accessible":false,
"description":"Please enter a description for this room",
"image":"https://www.mwtestconsultancy.co.uk/img/room1.jpg",
"roomPrice":"100",
"features":["WiFi"]
}

However, rather than getting the expected room creation back in an HTTP response, they receive a 500 Server Error message. The error leaves them feeling a bit frustrated. They go back to the documentation to see what we might have missed but learn nothing new. In the end, they decide that this API isn't working correctly and move on resulting in lost business for us.

4.1 How do we test API designs?

4.1.1 Tools for questioning

4.1.2 Expanding your API design testing techniques and tools

4.2 Using API documentation tools to test designs

4.2.1 Documenting APIs with Swagger

4.2.2 Beyond documentation

4.3 Encouraging teams to test API designs?

4.3.1 Getting buy-in and initiating opportunities to test API designs

4.3.2 Taking advantage of existing sessions

4.3.3 Establishing your own sessions

4.4 Testing API designs as part of a testing strategy

4.5 Summary