There are different ways to test your Controller (Web or API Layer) classes in Spring Boot, some provide support to write pure Unit Tests and some others are more intended to be used for Integration Tests. Within this post, I’ll cover the main three test approaches available for Spring: using MockMVC in standalone mode, MockMVC together with SpringRunner, and using SpringBootTest.
One of the main metrics for a software project is Test Coverage: if done properly, it gives you a quick picture about how much code is ‘protected’ by tests.
In this article, I’ll show you how to use a minimal configuration for including JaCoCo in our Spring Boot application, and how to process this information with Sonar.
Within this post, I show you how to setup properly a Unit Test in Spring Boot performing HTTP requests with Mockito. In this case, I’m testing directly against data to be placed into the model, but a similar test could be written for checking a REST API.
Sometimes testing web access with Spring Boot can be tricky. There are some specific annotations to be used, being the configuration to use maybe the most important one.