Interview questions
Question 138 of 254
FreeWhat is the difference between @WebMvcTest, @DataJpaTest, and @SpringBootTest?
Testing
@WebMvcTest loads only the Spring MVC web layer (controllers, filters, MVC-related config) with mocked service dependencies — fast, focused on testing request handling/serialization/validation. @DataJpaTest loads only the JPA-related infrastructure (repositories, an in-memory or configured test database, transaction handling) with automatic transaction rollback after each test — focused on testing the persistence layer. @SpringBootTest loads everything, for true end-to-end integration verification.
Advanced7 min
