MockK

Kotlin-native mocking library for JVM and Android. MockK uses Kotlin's reflection and coroutine support to provide idiomatic mocking — mockk<T>(), every { }, verify { }, coEvery { } for suspend functions. Unlike Mockito, MockK was built for Kotlin from the ground up: supports data classes, extension functions, object mocks, top-level function mocks, and coroutine-native coEvery/coVerify. The standard choice for mocking in Kotlin projects.

Evaluated Mar 06, 2026 (0d ago) v1.13+
Homepage ↗ Repo ↗ Developer Tools kotlin mocking testing coroutines android jvm unit-testing
&#9881; Agent Friendliness
66
/ 100
Can an agent use this?
&#128274; Security
87
/ 100
Is it safe for agents?
&#9889; Reliability
84
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
83
Auth Simplicity
95
Rate Limits
95

🔒 Security

TLS Enforcement
90
Auth Strength
88
Scope Granularity
85
Dep. Hygiene
85
Secret Handling
88

Test library — no direct security surface. Runs in JVM test sandbox. No network or credential handling.

⚡ Reliability

Uptime/SLA
88
Version Stability
84
Breaking Changes
80
Error Recovery
85
AF Security Reliability

Best When

You're writing Kotlin unit tests for code that uses coroutines, data classes, companion objects, or other Kotlin-specific patterns that Mockito handles poorly.

Avoid When

Your codebase is Java — Mockito has better Java ergonomics and larger Java ecosystem support.

Use Cases

  • Mock agent dependencies (API clients, repositories, services) in Kotlin unit tests with every { } stubbing and verify { } assertion blocks
  • Mock suspend functions and coroutine-based agent interfaces with coEvery { } and coVerify { } without runBlocking wrapper complexity
  • Mock companion objects, object singletons, and top-level Kotlin functions that Mockito cannot mock — critical for testing Kotlin idioms
  • Capture arguments passed to mocked agent methods using CapturingSlot<T> to assert on complex request objects
  • Use relaxed mocks (mockk<T>(relaxed = true)) for agent tests where you only care about specific interactions, not all method calls

Not For

  • Java-only projects — Mockito is better suited for Java; MockK's Kotlin DSL is awkward in Java
  • Android instrumented tests requiring framework mocking — Robolectric + Mockito handles Android framework mocking; MockK is for unit tests
  • Final class mocking in Java projects without inline mock maker — MockK handles Kotlin finals natively but Java finales need extra config

Interface

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

Authentication

Methods: none
OAuth: No Scopes: No

Test library — no authentication. Runs in JVM test environment.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Community-maintained open source. Apache 2.0 license.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • MockK mocks are not thread-safe by default — tests that use mock in multiple coroutines or threads concurrently may produce race conditions in verify { } counts
  • every { } stubbing uses reference equality by default — if your code creates new argument objects, use any() or custom matchers to avoid 'no answer found' NoSuchElementException
  • Android instrumented tests require mockk-android artifact, not mockk — using the wrong artifact causes ClassNotFoundException or runtime crashes on Android
  • mockkStatic and mockkObject require explicit unmockkStatic / unmockkAll cleanup after tests — stale static mocks leak between tests causing ordering-dependent failures
  • coEvery { } requires that the tested function is actually a suspend function — using coEvery on non-suspend functions throws UnnecessaryStubbingException or silently uses wrong stub
  • verify { exactly = 0 } works differently from verifyNever — and excludeRecords { } must be used to prevent verify(exactly = 0) from counting indirect mock interactions

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for MockK.

$99

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

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