On this page
Overview
MockK is a mocking library for Kotlin. Tests create doubles with mockk, define behavior with every, and verify interactions with verify. It also provides coroutine APIs, annotations, JUnit integration, and Android-specific artifacts.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Define strict mock behavior and verify interactions
Create a mock with mockk<T>(), stub behavior with every { ... } returns ..., and verify calls with verify { ... }. Mocks are strict by default, making unstubbed interactions explicit.
Sources: [2]
Use coroutine, annotation, and Android-specific APIs
coEvery and coVerify cover suspend functions, annotations such as @MockK integrate with JUnit helpers, and dedicated artifacts support Android unit and instrumented tests.
Sources: [2]
Best fit
Fits Kotlin unit tests that need explicit interaction verification
It is useful when services, repositories, and other collaborators should be replaced with test doubles and verified by arguments, calls, or behavior.
Sources: [2]
Before adoption
Inline functions and some JDK access patterns are limited
The README lists inline functions as non-mockable and notes access issues for some static or spy scenarios on JDK 16+, plus dynamic-agent warnings on JDK 21+.
Sources: [2]
Be cautious with spies around suspending functions
The documented known issues include unexpected results when combining spies with suspending functions. Prefer explicit mocks for coroutine tests and validate any spy-based case carefully.
Sources: [2]
Official sources
- [1]mockk/mockk repository(2026-09-30)
- [2]MockK v1.14.11 README(2026-09-30)
- [3]MockK v1.14.11 gradle.properties(2026-09-30)
- [4]MockK v1.14.11 release(2026-09-30)
- [5]MockK Apache 2.0 license(2026-09-30)
Supplemental curator note
MockK 1.14.11 is a Kotlin mocking library with strict mocks by default. every defines behavior and verify checks interactions, with coEvery/coVerify for coroutines and Android-specific artifacts available. Inline functions and some JVM access scenarios remain constrained.
Try it in 3 steps
- 1
Add MockK 1.14.11
Add the stable release as a Kotlin JVM test dependency. Use mockk-android when the Android-specific artifact is required.
testImplementation("io.mockk:mockk:1.14.11") - 2
Stub one behavior
Create a strict mock and define only the interaction needed by the test.
val service = mockk<Service>() every { service.load() } returns "ok" - 3
Verify the call
Execute the method and verify that the expected interaction occurred.
service.load() verify { service.load() }
Growth
Growth trends · Last 30 days
5,760 Stars
Trend data is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- argument-matchers
- chain-calls
- hacktoberfest
- kotlin
- matcher
- mock
- mocking-framework
- tdd
- testing
- verification
- Stars
- 5,760
- Forks
- 420
- Watchers
- 56
- Open issues
- 296
- Owner type
- Organization
- Primary language
- Kotlin
- License
- Apache-2.0
- Repository last updated
- Sep 29, 2026
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- fake-indexeddb695 Stars
1 shared tag(s) · 2 shared category(s)
recreate the IndexedDB API in memory for Node.js tests
JavaScript - RSpec117 Stars
1 shared tag(s) · 2 shared category(s)
describe Ruby behavior with examples, expectations, and test doubles and run it through a CLI
Ruby - Kotest4,789 Stars
3 shared tag(s) · 2 shared category(s) · Same language
combine spec styles, assertions, and property testing across Kotlin projects
Kotlin - Jest45,464 Stars
2 shared tag(s) · 2 shared category(s)
Combine assertions, mocks, watch mode, snapshots, coverage, and worker isolation in one JavaScript test runner
TypeScript - Vitest17,175 Stars
2 shared tag(s) · 2 shared category(s)
reuse Vite transforms and configuration across Node, DOM, and Browser Mode tests
TypeScript - Mockito15,456 Stars
2 shared tag(s) · 2 shared category(s)
replace Java collaborators and keep unit tests focused
Java
Report incorrect information
Tell us if any listing information is incorrect or outdated.