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.

Free to start · 7-day trial on paid plans

What you’ll be asked.

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.

Topics covered.

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.

Sample 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 AssertHired works.

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 1,200+ QA engineers already practicing with AssertHired.

Start your free QA interview
FREE.TO.START  ·  7.DAY.TRIAL ON PAID PLANS
Written by Aston Cook, Senior QA EngineerLast updated May 2026