← Spring Boot learning pathSpring Boot · Module 8 of 10
Testing Spring Boot
Write unit, slice and integration tests.
📖 Key ideas
- spring-boot-starter-test includes JUnit 5, Mockito and AssertJ.
- @SpringBootTest loads the full context.
- @WebMvcTest tests controllers with MockMvc.
- @DataJpaTest tests repositories with an in-memory DB.
- 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