Build
Connect & operate
Design & teams
Start hereScope a build in one callBring a spec, a wireframe, or a paragraph. You leave with an architecture, a timeline, and a number.Book a scoping call
AI software
LLM & data systems
Vibe coding
Ready to ship?Put AI where the work isAgents, RAG, and private LLMs wired into the systems your team already uses — not a chatbot bolted to a homepage.Discuss an AI project
Domain firstWe learn your workflow before we model itRegulated, operational, or high-volume — the constraints belong in the schema, not in a training doc.Talk about your domain
Plan smarterEstimate before you commitCost ranges, scope templates, and the questions we ask in discovery — free, no form.Open the cost calculator
Real conversationsTalk with a technical leadNo SDR, no discovery gauntlet. The person on the call is the one who scopes the build.Book a call
Open-Source Testing · mockito

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.

Source: GitHub — github.com/mockito/mockito
15.4k
GitHub stars
2.7k
Forks
Java
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorymockito/mockito
Ownermockito
Primary languageJava
LicenseMIT — OSI-approved
Stars15.4k
Forks2.7k
Open issues488
Latest releasev5.23.0 (2026-03-11)
Last updated2026-07-07
Sourcehttps://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.

Quickstart

Get the mockito source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/mockito/mockito.gitcd mockito# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Isolating external dependencies in unit tests

Mock third-party APIs, databases, and services to test business logic in isolation without requiring live connections or expensive integration setups.

Verifying method call sequences and interactions

Validate that objects communicate correctly by asserting which methods were called, in what order, and with what arguments—essential for behavior-driven testing.

Test-driven development (TDD) workflows

Define expected behavior upfront using mocks before implementing logic, supporting red-green-refactor cycles in agile and continuous integration pipelines.

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.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

mockito FAQ

Can I mock final classes or static methods?
Mockito v5 uses mockito-inline by default, enabling mocking of final classes and static methods (with caveats). Older versions required manual configuration. Static method mocking is limited and refactoring the design is often preferred.
Do I need to upgrade from Mockito 2.x or 3.x to 5.x?
Only if you require Java 11+. Mockito 2.x requires Java 6+; Mockito 3.x requires Java 8+; Mockito 5.x requires Java 11+. Older versions receive no updates; plan upgrades as part of Java version migrations.
What is the performance impact of Mockito in large test suites?
Mockito overhead is negligible for typical unit tests. If mock creation or bytecode manipulation is slow, profile to identify bottlenecks; usually indicates over-mocking or test design issues rather than framework limitation.
Does Mockito work with Spring Boot and dependency injection?
Yes. Spring Test provides @MockBean and @SpyBean annotations that use Mockito under the hood. Refer to Spring Boot test documentation for version compatibility and setup details.

Custom software development, end to end

If mockito is on your shortlist, DEV.co can build around it. We are a custom software development company covering architecture, implementation, and production operations for open-source testing workloads.

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.