Which test annotation starts the FULL Spring application context, and which loads only the web layer?
Options
@WebMvcTeststarts the full context;@SpringBootTestloads the web layer@SpringBootTeststarts the full context;@WebMvcTestloads the web layer (Correct option)- Both annotations always load the whole application context
@DataJpaTeststarts the full context of the application
Answer
@SpringBootTest is full; @WebMvcTest loads only controllers and web components (with MockMvc)
Why
@SpringBootTest starts the whole application: slow but realistic (integration tests).
Test slices load only the part you are testing, so they are faster:
@WebMvcTest(UserController.class): only the web layer; you mock services and call endpoints withMockMvc.@DataJpaTest: only JPA and repositories, with an in-memory database by default.
For pure unit tests of a service, skip Spring: use JUnit + Mockito.
Remember
Slices (@WebMvcTest, @DataJpaTest) are fast; @SpringBootTest is the full app.