Spring Boot 4 Testing / Part 3YOUTUBE PLAYER LOADS ON PLAYYour First Unit Test
Spring Boot Testing #3

JUnit 6 Tutorial for Beginners: First Unit Test with AssertJ and @ParameterizedTest

Spring Boot 4 Testing3 Nov 20263:54Open on YouTube

In this lesson

Last time, one small test caught a bug: Meera booked 4 seats and was charged ₹800 instead of ₹720. Today we read that test line by line and make it test every seat count at once.

Episode 2 of Spring Boot Testing: the complete guide. Same cinema booking app, one layer per episode.

  • What a unit test is: one small piece of code, tested on its own (no Spring, no database, no web server)
  • The three steps of every test: Arrange, Act, Assert
  • The BigDecimal trap: why isEqualTo("720") fails against 720.00, and why isEqualByComparingTo is right for money
  • @ParameterizedTest + @CsvSource: one test method, four inputs (1, 3, 4 and 6 seats)
  • Guess first: bring the old bug back. Which row turns red?

Next: Ep 3, testing the manager (BookingService) without a real database, using Mockito.

Built and run on Spring Boot 4.1, Java 21, JUnit 6, AssertJ 3.27.

Keep going

More walkthroughs.