mockito
Mockito is the most widely used mocking framework for Java unit testing, enabling developers to isolate and test code by creating mock objects. It simplifies test writing by allowing precise specification of object behavior and interaction verification. Available under MIT license with active maintenance and broad industry adoption.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | mockito/mockito |
| Owner | mockito |
| Primary language | Java |
| License | MIT — OSI-approved |
| Stars | 15.4k |
| Forks | 2.7k |
| Open issues | 488 |
| Latest release | v5.23.0 (2026-03-11) |
| Last updated | 2026-07-07 |
| Source | https://github.com/mockito/mockito |
What mockito is
Mockito provides a Java library for creating mock objects, stubbing method calls, and verifying interactions in unit tests. Version 5.x requires Java 11+, uses mockito-inline as the default mockmaker, and publishes automated releases to Maven Central monthly. The framework integrates with JUnit and other testing tools through standard dependency injection patterns.
Get the mockito source
Clone the repository and explore it locally.
git clone https://github.com/mockito/mockito.gitcd mockito# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Requires Java 11+; audit existing projects on Java 8 and plan migration or version pinning strategy.
- Mockito-inline is the default mockmaker since v5—verify compatibility with your bytecode manipulation tools and AOT/native compilation if used.
- No breaking API changes between major versions (3→4→5), but deprecated APIs removed in v4; review codebase for deprecated method usage.
- Test readability improves significantly with fluent API and argument matchers; invest in team training to avoid over-mocking and brittle tests.
- Performance overhead is minimal for unit tests; monitor if mock setup becomes a bottleneck in large test suites.
When to avoid it — and what to weigh
- You require Java versions below Java 11 — Mockito 5.x mandates Java 11 minimum. Older projects on Java 8 or 6 would need to remain on Mockito 2.x or 3.x respectively, which receive no updates.
- You need integration testing frameworks — Mockito is a unit-test isolation tool; it is not designed for end-to-end or integration testing where real service interactions are required.
- You have strict bytecode manipulation restrictions — Mockito uses Java bytecode manipulation (via cglib or Byte Buddy) which may conflict with security managers, sealed modules, or native compilation tools.
- Your codebase has heavy use of final classes or static methods — Mockito cannot directly mock final classes or static methods without workarounds, requiring refactoring or alternative testing strategies.
License & commercial use
Licensed under MIT (permissive OSI license). Allows unrestricted use, modification, and distribution in closed-source and commercial projects without obligation to release source code or provide attribution (though attribution is appreciated).
MIT license permits commercial use without restriction. Commercial support and maintenance available via Tidelift subscription for enterprise customers. No license fees required for use; support services are optional add-on.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
Mockito uses bytecode manipulation (cglib/Byte Buddy) which may interact with security managers or JVM restrictions; review if deployed in restricted environments. No known security advisories in provided data; consult security databases for latest CVE status. Does not introduce runtime dependencies beyond bytecode library; supply-chain risk minimal. Audit mocking behavior in tests does not accidentally bypass security controls.
Alternatives to consider
JMockit
Alternative mocking framework with different API and broader bytecode manipulation capabilities. Less widely adopted; smaller ecosystem.
EasyMock
Older mocking framework with record-and-replay style API. Less expressive syntax than Mockito; declining adoption in modern projects.
Spock Framework (Groovy)
Combines mocking and BDD-style test language; requires Groovy. Smaller community; better for projects already using Groovy DSL.
Build on mockito with DEV.co software developers
Integrate Mockito into your CI/CD pipeline today. Consult Devco's Java engineering specialists to design scalable test strategies for enterprise projects.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
mockito FAQ
Can I mock final classes or static methods?
Do I need to upgrade from Mockito 2.x or 3.x to 5.x?
What is the performance impact of Mockito in large test suites?
Does Mockito work with Spring Boot and dependency injection?
Work with a software development agency
DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If mockito is part of your open-source testing roadmap, our team can implement, customize, migrate, and maintain it.
Ready to strengthen your Java test suite?
Integrate Mockito into your CI/CD pipeline today. Consult Devco's Java engineering specialists to design scalable test strategies for enterprise projects.