Mockito Interview Questions
Interviewing for a Java SDET or developer role that uses Mockito? Practice with an AI that asks about mocks vs spies, stubbing with when/thenReturn, verifying interactions, argument matchers, and the pitfalls that trip people up.
No account needed · Scored in under a minute against a senior rubric
What do interviewers ask about Mockito?
Mockito interviews focus on the difference between a mock, a spy, and a stub, how you stub behavior with when/thenReturn (and doReturn for spies), and how you verify interactions with verify, times, never, and InOrder. Expect questions on argument matchers (any, eq, argThat) and the rule that you cannot mix raw values and matchers, on annotations (@Mock, @Spy, @InjectMocks) and the MockitoExtension, and on testing exceptions with thenThrow. Senior topics cover mocking static and final methods (mockito-inline), avoiding over-mocking, and why mocking what you do not own is a smell.
What do Mockito interviewers ask at junior, mid and senior level?
The same tool, three different interviews. Find your row before you prepare.
| Level | What interviewers probe | Typical question |
|---|---|---|
| Junior | What interviewers probeCreating a mock, stubbing a return value, verifying a call, and the difference between a mock and a spy. | Typical questionWhat is the difference between a mock and a spy in Mockito? |
| Mid-level | What interviewers probeArgument matchers and captors, stubbing exceptions, strict stubs, and injecting mocks into the class under test. | Typical questionHow would you verify a method was called with an object whose fields match specific values? |
| Senior | What interviewers probeOver-mocking as a design smell, testing behaviour versus interactions, and mocking policy across a codebase. | Typical questionA test suite mocks nearly every collaborator. What does that tell you about the code, and what would you change? |
Which Mockito topics come up most?
Key areas interviewers evaluate when asking about mockito.
Mocks, Spies & Stubs
The difference between a mock, a partial spy, and a stub, and when each is the right tool.
Stubbing Behaviour
when/thenReturn, thenThrow, doReturn for spies, consecutive returns, and stubbing voids.
Verifying Interactions
verify, times, never, atLeast, InOrder, and verifying no more interactions.
Argument Matchers
any, eq, argThat, the all-or-nothing matcher rule, and capturing arguments with ArgumentCaptor.
Annotations & Setup
@Mock, @Spy, @InjectMocks, MockitoExtension/JUnit integration, and avoiding stubbing leaks.
Pitfalls & Best Practice
Over-mocking, mocking types you do not own, mockito-inline for static/final, and keeping tests readable.
What are common Mockito interview questions?
Questions based on real interview patterns. Practice answering these with AssertHired’s AI interviewer.
- 01
What is the difference between a mock and a spy in Mockito? When would you use each?
- 02
How do you stub a method to return a value, and how is stubbing a spy different?
- 03
How do you verify that a method was called exactly twice, and never with a particular argument?
- 04
What is the rule about mixing argument matchers and raw values, and why does it exist?
- 05
How do @Mock, @Spy, and @InjectMocks work, and what does @InjectMocks actually do?
- 06
How would you test that a method throws an exception using Mockito?
- 07
How do you mock a static or final method, and why was that historically discouraged?
- 08
When is mocking a code smell? How do you avoid over-mocking?
Go Deeper on Mockito
Practice is free. These are the guides and project packs that turn the answers into working skills.
How does AssertHired help you practice Mockito questions?
Three steps. No fluff. Designed specifically for QA engineers.
Pick Your Focus
Choose from 6 QA-specific categories. Select your role, target company, and difficulty level to customize the experience.
Interview with AI
Answer 5 realistic interview questions from an AI that understands QA workflows, test architecture, and engineering culture.
Get Scored
Receive instant feedback scored across 4 dimensions: Technical Accuracy, Communication, Examples, and Depth of Knowledge.
Frequently Asked Questions
What is the difference between a mock and a spy?
A mock is a full test double with no real behavior unless you stub it. A spy wraps a real object and runs real methods unless you override specific ones. Use mocks to isolate completely; use spies sparingly when you need mostly-real behavior with a couple of overrides.
Why can you not mix matchers and raw values in Mockito?
Mockito uses matchers via a side-channel stack, so if one argument is a matcher, all must be. Mixing a raw value with a matcher throws InvalidUseOfMatchersException. Wrap raw values with eq() to fix it.
Is it bad practice to mock everything?
Yes. Over-mocking couples tests to implementation and hides real integration bugs. Prefer mocking at boundaries (network, database, time), use real objects for simple collaborators, and never mock types you do not own, wrap them instead.
Can I practice Mockito questions on AssertHired?
Yes. The AI interviewer asks Mockito mocking, verification, and best-practice questions with follow-ups and scores you across four dimensions.
Which Mockito terms should you know?
Concepts interviewers expect you to define alongside Mockito.
From the Blog
Related guides and tips to help you prepare.
More Languages for Testers Questions
Explore interview questions for related tools in this category.
Explore More Interview Prep Resources
Dive deeper into related QA interview topics.
Free QA career tools, no account needed
Instant and private, everything runs in your browser. Try them before you sign up.
QA Resume Checker
Instant 0-100 score on automation keywords, impact, and ATS formatting.
QA Cover Letter Generator
A tailored 3-paragraph QA cover letter from your resume and a job post.
QA Application Tracker
Drag-and-drop kanban to track every QA application from Applied to Offer.
QA Take-Home Test Generator
A realistic take-home assignment with a scenario, tasks, and a rubric.
QA LinkedIn Headline Generator
A recruiter-searchable headline, About section, and skills list.
QA STAR Story Builder
Structure a QA behavioral answer with the STAR method and instant checks.
QA Bug Report Generator
Build a clean, reproducible bug report for Markdown, Jira, or plain text.
Boundary Value Analysis Generator
Generate boundary value and equivalence partitioning test cases from a range.
QA Metrics Calculator
Calculate DRE, defect leakage, defect density, and pass rate with interpretation.
QA Test Plan Generator
Build a structured test plan (scope, approach, criteria, risks) in Markdown.
QA Salary Calculator
Estimate QA, SDET, and automation tester pay by level, market, and skills.
QA Offer Evaluator
See total comp, a counter range, and a ready-to-send negotiation message.
Ready for Your Mockito Interview?
Practice with AI that asks real Mockito mocking, verification, and Java testing questions.
Join 500+ QA engineers already practicing with AssertHired.
A test passes locally but fails in CI about one run in five. Walk me through what you check first, and why.
Scored on the same four dimensions as the real thing: Technical accuracy · Coverage · Clarity · Best practices.
Rather skip ahead? Create a free account