Annotation Loads Use for none (plain JUnit + Mockito) nothing services and domain logic — fastest @WebMvcTest(Controller.class) MVC layer only controllers, validation, JSON, security rules @DataJpaTest JPA + repositories queries and mappings @JsonTest Jackson serialisation @SpringBootTest whole context end-to-end slices, wiring Testcontainers (@ServiceConnection) real Postgres/Kafka/Redis in Docker realistic integration tests Mock collaborators in slice tests with @MockitoBean (Boot 3.4+; @MockBean earlier). Use MockMvc (or RestTestClient/WebTestClient) to call endpoints. Keep the pyramid: many fast unit tests, fewer slice tests, a handful of full integration tests.
Key Takeaways
Prefer plain unit tests; use slices like @WebMvcTest and @DataJpaTest for layers.
Mock collaborators in slice tests with @MockitoBean.
Assert status codes, JSON paths and headers with MockMvc.
Use Testcontainers with @ServiceConnection for realistic integration tests.