Slice annotations start only the layer under test, so the suite stays fast.
@WebMvcTest(OrderController.class) // web layer only, service is mocked
class OrderControllerTest {
@Autowired MockMvc mvc;
@MockitoBean OrderService service;
}
@DataJpaTest // JPA + in-memory DB only
class OrderRepositoryTest {
@Autowired OrderRepository repo;
}
@SpringBootTest // the WHOLE application context
class FullIntegrationTest { }
@WebMvcTest: ~0.4s per class
@SpringBootTest: seconds, and one context per distinct configuration
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11