Intermediate
Testing Java Services
Tests that catch the bugs that ship.
JUnit 5 and Mockito used well, the test pyramid for a service, Spring Boot test slices, Testcontainers for real databases and brokers, API and contract testing, and performance tests that produce a number you can act on.
3 lessons written4 outlined3 modules~1h reading
After this course you can
- Write unit tests that test behaviour and survive a refactor
- Use @WebMvcTest, @DataJpaTest and @SpringBootTest for what each is for
- Run integration tests against a real Postgres and Kafka with Testcontainers
- Load-test an endpoint and read the percentiles
Curriculum
7 lessons · outlined lessons show their plan01
What is worth a testA test that mocks the thing under test passes while the bug ships. Rules, boundaries, and asserting on behaviour rather than on which methods were called.12 minThe test pyramidThe shape is a consequence of cost, measured on this project: five in-process guards in 1.9 seconds, two container-based ones in 54.10 minFlaky testsWorse than no test, because they teach a team that red does not mean broken — with a real one from this codebase, diagnosed rather than retried.12 minStrategy
02
JUnit 5 and MockitoLifecycle, parameterised tests, assertions worth reading, mocks versus stubs versus fakes, and the over-mocked test that tests nothing.outlinedSpring Boot test slices@WebMvcTest with MockMvc, @DataJpaTest, @SpringBootTest with a random port, and keeping the context cache warm.outlinedUnit and slice tests
03
TestcontainersReal Postgres, Kafka and Redis in tests, container reuse, and the CI configuration that makes it fast.outlinedAPI, contract and performance testingREST Assured, consumer-driven contracts with Pact, and Gatling or k6 for the percentile that matters.outlined