Testing RESTful routes

So far, we have added tests for routes. Now, let's take a look at how we can test our ShoppingListController. To test our controller, we would need to write test for each of the RESTful actions and assert that the result at the end of the action is as expected. To make our code modular, it would be good to create a separate test file for these tests. So, to get started writing tests for our Shopping List Controller, follow these steps:

  1. Create a new empty file called ShoppingListControllerTests.swift inside the Tests/AppTests folder and make sure that you add it to the AppTests target.
  2. Inside this file, add the following lines of code; this will import the required modules for testing, and we will define our test class: ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.