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

Spring Boot 4 Testing4 Nov 20264:49Open on YouTube

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.

Keep going

More walkthroughs.