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
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.
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.
Spring Boot Testcontainers Tutorial: Test the Whole App on Real Postgres, 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.
