Spring Boot 4 Testing / Part 7YOUTUBE PLAYER LOADS ON PLAY@SpringBootTest + Testcontainers
Spring Boot Testing #7
Spring Boot Testcontainers Tutorial: Test the Whole App on Real Postgres
In this lesson
Every floor of our cinema app passed its own test, but each time something was pretend: a stand-in manager, a pretend customer, a small in-memory database. Today nothing is fake: we test the whole app together, on a real Postgres running in Docker.
Episode 6 of Spring Boot Testing: the complete guide. Same cinema booking app, one layer per episode.
- How Spring finds each part: @RestController, @Service, @SpringBootApplication, and why a JpaRepository interface doesn't need @Repository
- @Entity, @Id and @GeneratedValue in plain words
- Docker in plain words: image = the recipe, container = one running copy
- Testcontainers: a real Postgres 17 for your tests, thrown away after
- @SpringBootTest, @AutoConfigureMockMvc, @Testcontainers, @Container and @ServiceConnection, line by line
- @BeforeEach / @AfterEach: why we clean up ourselves here (no automatic rollback)
- Version notes: Testcontainers 2 artifact and package names, @DynamicPropertySource vs @ServiceConnection, Spring Boot 4's new @AutoConfigureMockMvc package
- Guess first: we delete @ServiceConnection. Do the tests still pass? (Yes, and that's the problem.)
Next: Ep 7, the last one: the most common testing mistakes, and one map of which test to use and when.
Built and run on Spring Boot 4.1, Java 21, JUnit 6, Testcontainers 2.0, PostgreSQL 17.
Chapters
Spring Boot 4 Testing, 9 out
1Spring Boot Testing Tutorial for Beginners: The App, HTTP and Boot 3 vs 43:312Why Write Tests? The Test Pyramid Explained with One Real Bug3:123JUnit 6 Tutorial for Beginners: First Unit Test with AssertJ and @ParameterizedTest3:544Mockito Tutorial for Beginners: Test a Spring Boot Service Without a Database3:405Spring Boot 4 Controller Test: @WebMvcTest and MockMvc Tutorial3:256Spring Boot @DataJpaTest Tutorial: Test JPA Queries on a Real Database4:197Spring Boot Testcontainers Tutorial: Test the Whole App on Real Postgres4:4983 Spring Boot Testing Mistakes: The Test Passes but the Price Is Wrong4:149Test a Spring Boot Controller: @WebMvcTest + MockMvc0:57Keep going
More walkthroughs.
3 Spring Boot Testing Mistakes: The Test Passes but the Price Is Wrong, Video.
Spring Boot @DataJpaTest Tutorial: Test JPA Queries on a Real Database, Video.
Spring Boot 4 Controller Test: @WebMvcTest and MockMvc Tutorial, Video.
Mockito Tutorial for Beginners: Test a Spring Boot Service Without a Database, Video.
