roadmap
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
Prepare for Mockito interview questions on how mocks record calls, return stubbed answers and verify interactions. Covers spies, matchers and captors, static and final mocking, and strict stubbing.
132 of 132 questions in your plan: 0 known, 0 in progress, 0 due, 0 skipped, 132 new. 0 cut, outside your plan.
Mockito rarely gets a round of its own. It surfaces inside the testing part of Java and Android interviews: a live exercise where you write a unit test for a service whose repository and mail client have to be faked, or a review of a test that stays green while the code under it is broken. From there the questions go to the mechanism behind a symptom. Why does stubbing get(0) with when on a spy of an empty list throw before the stub is recorded? Why does passing eq() for one argument and a raw value for the other end in InvalidUseOfMatchersException? Why is the field marked @InjectMocks still null, and why did a stub that looks harmless fail the test with UnnecessaryStubbingException after a move to MockitoExtension?
The opening questions check that you can stub a return value, verify a call and say how a mock differs from a spy. The follow-ups ask how the library works underneath: when() sees only the last call made on a mock, which is why matchers sit on a hidden stack and why a spy's real method runs inside the stubbing call, and the inline mock maker is what lets Mockito intercept final classes and static methods at all. Questions that decide a senior hire are about judgment more than API: when a test full of verify calls is the implementation written twice, which types should never be mocked, and when a strict-stubbing failure points at a real smell rather than noise.
The plan opens on vocabulary rather than on the library. Test doubles, the stubs, fakes, mocks and spies of the Meszaros taxonomy, come first because Mockito calls nearly everything a mock, and a candidate who cannot say which role an object plays in a test misreads the API that follows. The setup stretch comes next: how a JUnit extension is registered, since @ExtendWith(MockitoExtension.class) is what turns Mockito's annotations into live objects, then creating mocks, spies and the injected subject, along with the quiet ways that wiring fails.
With doubles in hand, the plan gives them behavior and then checks it. Stubbing sets the two syntaxes side by side, when and the do-family, and shows why spies and void methods need the second. Matchers and captors follow because the same argument rules apply on both sides of a test: when a stub is set up, and when a call is verified for its count, its order or its timing.
Advanced mocking is placed after the everyday API on purpose. Static and constructor mocks, final types and deep stubs are escape hatches, and the scoped MockedStatic handle only makes sense once ordinary stubbing does. The plan closes on strictness and hygiene, where everything before it is judged: what strict stubs report, which collaborators deserve a mock at all, and how Mockito's naming maps back onto the vocabulary the plan began with.
Begin with the test you would write on a whiteboard: one service, one collaborator to stub, one call to verify. If you can write it without looking anything up, the setup, stubbing and verification modules are review, and your hours go further where working tests still fail in surprising ways: [the all-or-none matcher rule](/topics/dev-mockito-matchers-captors-all-or-none), the do-family on spies, and what strict stubs report after a refactor. If you cannot, work through those three modules first with importance raised to must know. SDET candidates and anyone who reviews test code for a living should switch study order to by topics and reach the last module, because the questions there are arguments about design: overmocking, mocking types you do not own, a `verify` that only restates the code. JUnit, the runner these tests execute in, appears here only as the extension hook Mockito plugs into, and the language beneath both belongs to the [Java roadmap](/roadmaps/java). Replacing a bean in a Spring context with a mock is Spring's own test support, covered by the [Spring Boot roadmap](/roadmaps/spring-boot). Kotlin teams often reach for MockK, a separate library, which the [Kotlin Backend Developer roadmap](/roadmaps/kotlin-developer) carries beside the rest of its JVM test tooling.
Begin with the test you would write on a whiteboard: one service, one collaborator to stub, one call to verify. If you can write it without looking anything up, the setup, stubbing and verification modules are review, and your hours go further where working tests still fail in surprising ways: the all-or-none matcher rule, the do-family on spies, and what strict stubs report after a refactor. If you cannot, work through those three modules first with importance raised to must know. SDET candidates and anyone who reviews test code for a living should switch study order to by topics and reach the last module, because the questions there are arguments about design: overmocking, mocking types you do not own, a verify that only restates the code.
JUnit, the runner these tests execute in, appears here only as the extension hook Mockito plugs into, and the language beneath both belongs to the Java roadmap. Replacing a bean in a Spring context with a mock is Spring's own test support, covered by the Spring Boot roadmap. Kotlin teams often reach for MockK, a separate library, which the Kotlin Backend Developer roadmap carries beside the rest of its JVM test tooling.