← Spring Boot learning path
Spring Boot · Module 8 of 10

Testing Spring Boot

Write unit, slice and integration tests.

📖 Key ideas

  1. spring-boot-starter-test includes JUnit 5, Mockito and AssertJ.
  2. @SpringBootTest loads the full context.
  3. @WebMvcTest tests controllers with MockMvc.
  4. @DataJpaTest tests repositories with an in-memory DB.
  5. Testcontainers runs real databases in Docker for tests.
💡 Real-life example: Slice tests are checking one room of a house instead of inspecting the whole building each time.
JUnit 5Java testing framework
MockitoCreates mock objects
MockMvcTests MVC controllers
TestcontainersReal services in Docker for tests