Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 65
Integration Testing
Integration tests spin up a slice (or all) of the Spring context against real dependencies — best done with Testcontainers for Postgres, Redis, Kafka.
Course progress0%
Focus
2 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Integration tests spin up a slice (or all) of the Spring context against real dependencies — best done with Testcontainers for Postgres, Redis, Kafka.
Informative example
ts
@SpringBootTest@Testcontainers@AutoConfigureMockMvcclass OrderApiIT {@Containerstatic PostgreSQLContainer<?> pg = new PostgreSQLContainer<>("postgres:16");@DynamicPropertySourcestatic void props(DynamicPropertyRegistry r) {r.add("spring.datasource.url", pg::getJdbcUrl);r.add("spring.datasource.username", pg::getUsername);r.add("spring.datasource.password", pg::getPassword);}@Autowired MockMvc mvc;@Test @WithMockUser(roles = "USER")void createsOrder() throws Exception {mvc.perform(post("/api/v1/orders").contentType(APPLICATION_JSON).content("""{ "userId": 1, "items": [{"productId":10,"qty":2}], "currency":"USD" }""")).andExpect(status().isCreated()).andExpect(jsonPath("$.status").value("PLACED"));}}
Ready to mark this lesson complete?Track your journey across the entire course.