Spring Boot 4 Testing / Part 8YOUTUBE PLAYER LOADS ON PLAYThis Test Passes and the Price
Spring Boot Testing #8

3 Spring Boot Testing Mistakes: The Test Passes but the Price Is Wrong

Spring Boot 4 Testing4 Nov 20264:14Open on YouTube

In this lesson

A test that passes while the price is wrong. A test that passes alone and fails with the others. A test that takes 10 seconds to multiply two numbers. Three testing mistakes almost everyone makes, each run for real on our cinema app, and one map of which test to use, and when.

Episode 7 of Spring Boot Testing: the complete guide. The last episode. Same cinema booking app from Episode 1.

  • Mistake 1: a test with no assert can never fail (it passed with the wrong price, 800.00)
  • Mistake 2: tests that leave data behind (passes alone, fails together: 201 expected, 409 received)
  • Mistake 3: @SpringBootTest for everything (10.37 s vs 0.004 s for the same check)
  • Every name that changed in this series: @MockBean to @MockitoBean, the split test starters, new packages for @WebMvcTest and @DataJpaTest, Testcontainers 2, @ServiceConnection, JUnit 6
  • The map: unit test, Mockito, @WebMvcTest, @DataJpaTest or @SpringBootTest + Testcontainers?
  • The whole suite: 16 tests, all green

Built and run on Spring Boot 4.1, Java 21, JUnit 6, Mockito 5, Testcontainers 2.0, PostgreSQL 17.

Keep going

More walkthroughs.