
Mockito
A Java library for creating fake test objects so unit tests can run in isolation.
- Stars
- 15.5k
- Forks
- 2.7k
- Licence
- MIT
- Language
- Java
- Last update
- 7 days ago
- Type
- Library
What it is
Mockito is a Java library that lets developers create stand-in objects, called mocks, for parts of a program their tests depend on. This lets a test check one piece of code on its own, without a real database or network service. The README describes it as the most popular mocking framework for Java and says it is hosted on Maven Central under org.mockito:mockito-core.
- Replace a database or web-service dependency with a mock so a unit test runs quickly without it
- Verify that a method was called with particular arguments
- Stub return values so a test can cover a specific branch of logic
Great for
- Java developers writing unit tests for classes with external dependencies
- Teams that want a widely used, well-documented mocking library
- Students learning test-driven development in Java
Not ideal for
- Projects not written in Java, since this is a Java library (the README does not cover other languages)
- Developers on Java 8 or older, because Mockito 5 requires Java 11 according to the README
- Teams needing paid support from the maintainers, which the README only offers through a third-party Tidelift subscription
How to get it
- 1
Install with a package manager
You'll need: Java 11 or newer (per the README's note on Mockito 5) · A build tool such as Gradle or Maven to fetch the library from Maven Central
Clone the repository
git clone https://github.com/mockito/mockito.git - 2
Run it
- Add org.mockito:mockito-core to your project's dependencies through Maven Central
- Write a unit test in your project and create a mock object for a dependency
- Run your test suite with your normal build tool
- 3
Get the most out of it
- Read the documentation on javadoc.io and the Mockito site at site.mockito.org
- Check the Contributing Guide if you want to report issues or contribute code
- Follow the Semantic Versioning notes to understand how upgrades will affect your code
Downloads
Strengths
- Widely used, with a large community and many questions answered on Stack Overflow
- MIT licensed and actively maintained, with a recent push to the repository
- Has an official documentation site and javadoc hosted online
Trade-offs
- Only one major version is supported at a time, and fixes are not backported to older versions
- Mockito 5 requires Java 11 or newer, which may rule it out for older projects
- The README is truncated here, so specific API details are not covered in this entry
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| mockito (this) | 15.5k | Library | beginner | 7 days ago | Java developers writing unit tests for classes with external dependencies |
| msw | 18.3k | Library | intermediate | 20 days ago | Frontend developers who need to work before a backend API is ready |
| Detox | 12.1k | Library | intermediate | 4 days ago | Teams building React Native apps for Android and iOS who want automated end-to-end tests |
| testify | 26.2k | Library | beginner | 18 days ago | Go developers who want more readable test assertions than the standard library provides |
| learn-go-with-tests | 23.9k | Learning resource | beginner | 11 days ago | Developers who are new to Go and want a guided, hands-on tutorial |
| mocha | 22.9k | Library | intermediate | 5 days ago | JavaScript and Node.js developers who want automated tests for their code |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.