mockk
MockK is a Kotlin-native mocking library for unit testing that provides a DSL-based syntax for creating mocks, defining behavior, and verifying interactions. It supports both JVM and Android platforms with optional BDD-style aliases and integrates with Spring and Quarkus.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | mockk/mockk |
| Owner | mockk |
| Primary language | Kotlin |
| License | Apache-2.0 — OSI-approved |
| Stars | 5.7k |
| Forks | 412 |
| Open issues | 303 |
| Latest release | v1.14.11 (2026-05-29) |
| Last updated | 2026-07-02 |
| Source | https://github.com/mockk/mockk |
What mockk is
MockK uses bytecode manipulation and reflection (via an agent) to mock Kotlin classes, including support for coroutines, inline functions (with limitations), relaxed mocks, and spy objects. It distributes via Maven Central with separate artifacts for JVM (mockk-jvm) and Android (mockk-android + mockk-agent).
Get the mockk source
Clone the repository and explore it locally.
git clone https://github.com/mockk/mockk.gitcd mockk# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- MockK requires inclusion of mockk-agent artifact on classpath/in buildpath to enable bytecode manipulation; agent setup varies between Gradle/Maven and IDE environments.
- Strict mocks by default: all method calls must have explicit behavior defined via 'every { }' blocks or they throw exceptions; 'relaxed mocks' ease this but reduce verification strictness.
- Coroutine support via coEvery/coVerify requires understanding of suspend functions and test scope lifecycle; test framework integration (JUnit 4/5) matters for proper coroutine context.
- Spy objects (SpyK) partially delegate to real implementations; behavior differs from pure mocks and can lead to subtle test failures if real code has side effects.
- Matrix testing and multiple Kotlin version support (1.4+) requires explicit dependency version pinning; version mismatches can cause bytecode loading failures.
When to avoid it — and what to weigh
- Heavy Reliance on PowerMock Patterns — Known compatibility issues with PowerMock; workarounds exist but general usability after mitigation is unclear per README. If your codebase heavily depends on PowerMock's advanced features, consider isolation or alternatives.
- Extensive Inline Function Mocking — Inline functions cannot be mocked in Kotlin due to language-level compilation; MockK cannot work around this. If your architecture relies heavily on inlined utility functions, mocking becomes impossible.
- JDK 16+ with Static Mocks — mockkStatic and spies may fail on JDK 16+ with InaccessibleObjectException due to Java module system restrictions. Workarounds documented but require additional setup; Java 8–11 environments preferred.
- Non-Kotlin Codebases — MockK is Kotlin-specific and optimized for Kotlin semantics. Java-only projects should use Mockito, EasyMock, or similar Java mocking frameworks.
License & commercial use
MockK is licensed under Apache License 2.0 (Apache-2.0), a permissive OSI-approved open-source license that permits commercial use, modification, and distribution with attribution and liability disclaimer.
Apache 2.0 explicitly permits commercial use in proprietary products. No license fees, vendor lock-in, or per-seat restrictions. Code modifications can be closed-source if redistribution is not required. Consult your legal team if bundling MockK binaries in a commercial product offering; Apache 2.0 requires license/attribution notices in distribution.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
MockK uses bytecode manipulation and reflection via an agent loaded on JVM startup; review agent code if running in high-security environments (e.g., financial, healthcare). No security vulnerabilities disclosed in README. Agent operates only during test execution (test scope), not in production. Verify dependency integrity via Maven Central checksums. Third-party Spring/Quarkus extensions (springmockk, quarkus-mockk) should be vetted separately.
Alternatives to consider
Mockito
Mature Java mocking framework with limited Kotlin ergonomics; does not leverage Kotlin language features (extension functions, coroutines) as naturally as MockK. Preferred for Java-centric teams but less idiomatic in Kotlin codebases.
EasyMock
Record/replay model less intuitive for modern TDD workflows compared to MockK's DSL. Primarily Java-focused; weaker Kotlin support. Use case: teams with existing EasyMock infrastructure reluctant to migrate.
JMockit
Supports static/final method mocking via bytecode manipulation but heavier overhead and steeper learning curve than MockK. Declining adoption in Kotlin ecosystem; use case: legacy codebases requiring static mock capabilities unavailable in MockK.
Build on mockk with DEV.co software developers
MockK delivers Kotlin-native mocking with strong community adoption and active maintenance. Start with the quick-start Gradle dependency and Kotlin Academy guides. For Spring/Quarkus integration, review springmockk and quarkus-mockk separately. Contact Devco for custom test infrastructure assessment.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
mockk FAQ
Can I use MockK in production code?
Do I need to download and manage the MockK agent separately?
What is the difference between a strict mock and a relaxed mock?
Why can't MockK mock inline functions?
Software developers & web developers for hire
Need help beyond evaluating mockk? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and open-source testing integrations — and maintain them long-term.
Evaluate MockK for Your Kotlin Test Suite
MockK delivers Kotlin-native mocking with strong community adoption and active maintenance. Start with the quick-start Gradle dependency and Kotlin Academy guides. For Spring/Quarkus integration, review springmockk and quarkus-mockk separately. Contact Devco for custom test infrastructure assessment.