Mockito

Most popular Java mocking framework for unit testing. Creates mock objects, stubs method calls (when().thenReturn()), and verifies interactions (verify()). Works with JUnit 5 via @ExtendWith(MockitoExtension.class) or Spring's @MockBean. Mockito's fluent API makes test setup readable and concise — the standard for Java unit testing with mocks.

Evaluated Mar 06, 2026 (0d ago) v5.x
Homepage ↗ Repo ↗ Developer Tools java kotlin mockito mocking unit-test stubbing verification jvm
⚙ Agent Friendliness
69
/ 100
Can an agent use this?
🔒 Security
99
/ 100
Is it safe for agents?
⚡ Reliability
90
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
88
Error Messages
85
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
92
Secret Handling
100

Local testing library. No external calls. No security surface.

⚡ Reliability

Uptime/SLA
98
Version Stability
88
Breaking Changes
85
Error Recovery
90
AF Security Reliability

Best When

You're writing Java or Kotlin unit tests that need mock objects for dependency isolation — Mockito is the de facto standard for JVM mocking.

Avoid When

You need to mock static methods heavily (consider restructuring code), or you're doing integration testing where real implementations are better.

Use Cases

  • Create mock objects for dependencies in Java unit tests to isolate the class under test from external systems
  • Stub method calls on mocks (when(service.get(id)).thenReturn(entity)) for controlled test scenarios
  • Verify that methods were called on mocks with expected arguments for behavior-driven testing
  • Use @Mock, @InjectMocks, @Captor annotations with MockitoExtension for annotation-based mock injection
  • Mock Kotlin classes and data classes with mockito-kotlin for idiomatic Kotlin test code

Not For

  • Mocking static methods or final classes without configuration — requires Mockito's inline mock maker extension
  • Integration tests with real implementations — use Testcontainers for real service integration
  • Spying on complex objects with many methods — Spring's MockBean may be more appropriate in integration contexts

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Testing library. No authentication required.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT license.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • Mockito 5.x requires Java 11+ — Mockito 4.x for Java 8 compatibility
  • Kotlin data classes and final classes require mockito-kotlin library or mockito-inline configuration — Mockito cannot mock final classes by default
  • Argument matchers (any(), eq()) must be used consistently — mixing matchers with raw values in one stubbing call causes InvalidUseOfMatchersException
  • verify() does not check stubbing — a method can be stubbed and never called without verification failure; verify() must be explicit
  • MockitoExtension vs MockitoAnnotations.openMocks() — JUnit 5 uses @ExtendWith(MockitoExtension.class); JUnit 4 uses MockitoAnnotations.initMocks(this)
  • Spy objects (@Spy) call real methods unless stubbed — unstubbed spy methods may cause side effects; prefer mocks for isolated unit tests

Alternatives

Full Evaluation Report

Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for Mockito.

AI-powered analysis · PDF + markdown · Delivered within 30 minutes

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-06.

5229
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered