RESTful API testing
There are two ways to test a RESTful API. The first way is to test a RESTful API of a running application that is deployed to a server. In this approach, the test code acts as the client of the API. This is usually called an integration test because it tests all of the code that's involved in that the API's execution. Normally, the integration test is executed at a late stage, during Continuous Delivery (CD).
The second way is to isolate the API handler itself, using mocks for its dependencies and writing code to test the logic of the API handler. This is called unit testing and is where we have control of the dependencies and hence can expect the result of the execution to be precisely what we want. This is the approach we will use to test the RESTful API.
Unit testing of the Messages App
In Chapter 2, Vue.js 2 – It Works in the Way You Expected, we created a Messages App that has an API to retrieve all of the messages that are received. In this section, we will write unit...