Chapter plan
What you will complete
01Prove Domain Rules with JUnit 5Write small tests around state transitions, invariants, and edge cases without starting Spring.Construct the object graph directlyName tests after behavior and outcomeKeep time, randomness, and IDs controllable 35 min02Use Mockito for Collaborations, Not StateMock true boundaries and verify important messages without mirroring implementation steps.Prefer real value objectsStub only observations needed by the behaviorAvoid overspecified interaction scripts 35 min03Use MVC, JSON & JPA Test SlicesLoad focused framework infrastructure and understand exactly what each slice excludes.Use `@WebMvcTest` for HTTP mapping and error contractsUse `@DataJpaTest` for mappings and queriesImport only the additional collaborators the slice requires 45 min04Integrate with Real Services Using TestcontainersRun repeatable PostgreSQL, Redis, and broker tests with production-compatible behavior.Reuse migrations in testsWait for service readiness, not fixed sleepsKeep container state isolated between tests 50 min
Module outcome
Choose the narrowest test that can prove each risk and keep the suite deterministic.
Mental model
A test owns only the infrastructure needed to observe one important behavior; wider context is justified by wider integration risk.
Module checkpoint
Confidence suite
Build a test portfolio for the task API mapped to explicit production risks.
- Fast domain suite
- MVC and JPA slices
- PostgreSQL Testcontainer integration
Final module assessment
Ready to prove mastery?
Complete all 50 questions after finishing the module lessons and checkpoint.