Testing a RESTful API
Testing the application manually can be tiring, especially when dealing with challenging scenarios that are hard to validate. Additionally, it lacks scalability in terms of development productivity. Hence, I highly recommend applying automated testing.
By default, Spring Boot includes the Testing starter that provides the basic components for unit and integration testing. In this recipe, we’ll learn how to implement a unit test for our RESTful API.
Getting ready
In this recipe, we’ll create unit tests for the RESTful API created in the previous recipe. I prepared a working version in case you haven’t completed it yet. You can find it in the book’s GitHub repository at https://github.com/PacktPublishing/Spring-Boot-3.0-Cookbook/. You can find the code to start this recipe in the chapter1/recipe1-4/start
folder.
How to do it...
Let’s add some tests to our RESTful API that will validate our application whenever we...