@SpringBootTest khởi động full ApplicationContext — load toàn bộ bean, auto-config, DB... như production; thường kèm @AutoConfigureMockMvc để gọi endpoint qua MockMvc không cần server thật.
| Unit test | @SpringBootTest | |
|---|---|---|
| Context | Không có Spring | Full ApplicationContext |
| Tốc độ | Nhanh (~ms) | Chậm (~5-30s startup) |
| DB | Mock/in-memory | Real hoặc Testcontainers |
Modes: webEnvironment = MOCK (default — MockMvc, không mở port) · RANDOM_PORT (server thật, test bằng TestRestTemplate).
Best practice: dùng ít thôi (chậm, context cache dễ vỡ) — dành cho integration test full-flow; còn lại ưu tiên slice tests (@WebMvcTest, @DataJpaTest) load đúng layer cần test.