JUnit and Mockito
You opened a Java repo, saw a src/test/java folder full of @Test methods and mock(...) calls, and felt the familiar dread: which annotation does what, why is half the test setting up fake objects, and how do you write one of these yourself without copy-pasting the rest of the suite. This guide gives you the two tools that 90% of Java test code is built from, and the mental model to use them without drowning in mocks.
How to read this
Read the phases in order. Phase 1 builds the JUnit 5 mental model so the annotations stop being noise. Phase 2 puts Mockito next to it and shows the everyday isolate-the-unit workflow. Phase 3 is the part nobody warns you about: the ways these tools quietly lie to you, and how to keep your tests honest. If you've never written a unit test at all, /guides/your-first-unit-test is the gentler on-ramp; come back here for the Java specifics.
The phases
- What JUnit 5 actually is - the Jupiter model,
@Test, lifecycle, and assertions. - Mocking with Mockito - isolate the unit, stub collaborators, verify interactions.
- When tests lie - the mock-too-much trap, brittle verification, and production reality.