Spring Boot – How do you test your controllers?
Hey there! Welcome to this new blog post!
There are multiple testing methods out there. But in this post I would like to talk about the 2 most commonly used testing methods, which are:
- Integration testing
- Unit testing
1) Integration testing
Integration testing means we test a part of a system and its modules together as a group. We do not isolate the different modules that belong in a certain flow. Instead, we make sure to test all of them and check if we get the desired outcome.
For instance, looking at this common flow:
HTTP request -> Controller -> Service -> Repository -> Data
we would test the system from the front to the back including every layer along the flow.
2) Unit testing
Unit testing means that we test every module of a particular system flow in isolation as a “unit”, hence the name Unit Testing.
Considering the same flow mentioned above in the Integration test section, namely HTTP request -> Controller -> Service -> Repository -> Data
We would write separate tests for each unit:
- the controller
- the service
- the repository.
In the following, I will explain how this is achievable in the Spring Boot framework and what modules have to be used.
Kom in contact met ons als je vragen hebt of wanneer je klaar bent om gezamenlijk een project te starten!