Skip to main content
Mockito
INTERVIEW QUESTIONS  /  mockito

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.

Mockito interview questions by level: junior, mid-level and senior
JuniorWhat 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-levelWhat 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?
SeniorWhat 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.

  1. 01

    What is the difference between a mock and a spy in Mockito? When would you use each?

  2. 02

    How do you stub a method to return a value, and how is stubbing a spy different?

  3. 03

    How do you verify that a method was called exactly twice, and never with a particular argument?

  4. 04

    What is the rule about mixing argument matchers and raw values, and why does it exist?

  5. 05

    How do @Mock, @Spy, and @InjectMocks work, and what does @InjectMocks actually do?

  6. 06

    How would you test that a method throws an exception using Mockito?

  7. 07

    How do you mock a static or final method, and why was that historically discouraged?

  8. 08

    When is mocking a code smell? How do you avoid over-mocking?

How does AssertHired help you practice Mockito questions?

Three steps. No fluff. Designed specifically for QA engineers.

Step 01

Pick Your Focus

Choose from 6 QA-specific categories. Select your role, target company, and difficulty level to customize the experience.

Step 02

Interview with AI

Answer 5 realistic interview questions from an AI that understands QA workflows, test architecture, and engineering culture.

Step 03

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.

From the Blog

Related guides and tips to help you prepare.

Explore More Interview Prep Resources

Dive deeper into related QA interview topics.

FREE TOOLS  /  no signup

Free QA career tools, no account needed

Instant and private, everything runs in your browser. Try them before you sign up.

EXEC.NOW

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.

Question 1 · Automation · Mid-levellive scoring

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

FREE.TO.START  ·  7.DAY.TRIAL ON PAID PLANS