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.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Local testing library. No external calls. No security surface.
⚡ 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
Authentication
Testing library. No authentication required.
Pricing
MIT license.
Agent Metadata
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
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.