What is Mockito, and why is it used in unit testing?

Mockito is a Java mocking framework that creates test doubles for a class's dependencies, letting you test a unit of code in isolation from the real implementations it collaborates with.

Key Points

Example

Instead of hitting a real payment API in a unit test, you mock the PaymentClient so charge() always returns a controlled success or failure response.

Interview Tip

A concise interview answer is

Mockito is a mocking framework that lets me replace a class's real dependencies with configurable fake objects, so I can test business logic in isolation without touching databases, networks, or other slow external systems. It's central to writing fast, deterministic unit tests.

Last updated: 16 July 2026

Next question: How do you mock an object in Mockito?

More Mockito interview questions

All Mockito questions