Application Programming Interfaces (APIs) are interfaces that allow communications between different systems or layers of an application.
Applications often have 3 layers: a data layer (database), service layer (API/business logic), and presentation (UI) layer.
This means that testing APIs indirectly help with testing both data and presentation layers.
API testing is divided into 2 categories:
- Component test (Endpoint test) – this involves testing a single endpoint directly
- Integration test (Workflow test) – this involves testing multiple endpoints in order to test end-to-end scenarios.
There are 2 ways to verify that API is working as expected:
- Verifying status code – By checking the status code returned from invoking API, tester will be able to determine whether the test was successful or not. There are 5 categories/groups of status codes. Successful status code is in the 2XX status code group. 4XX status group indicates that there was an error in the request and 5XX status group indicates that there was a server issue and was unable to process the request.
- Verifying the value – This means inspecting and verifying the response returned from the API invocation for a particular value or the entire response itself.