MockK is a mocking library for Kotlin that provides a DSL-based approach to creating and verifying mock objects in unit tests.
The library addresses the need for Kotlin-native mocking by offering a fluent, type-safe syntax tailored to Kotlin's language features. It works by allowing developers to define mock behavior using expressions like `every { ... }` for stubbing and `verify { ... }` for assertion, with support for both standard and coroutine-based mocking through `coEvery` and `coVerify`. The tool enforces strict mocking by default, requiring explicit behavior specification before use. For teams practicing Behavior-Driven Development, MockK provides BDD-style aliases that map standard operations to more readable names like `given`, `coGiven`, `then`, and `coThen`.
Developers should choose MockK if they are building Kotlin applications and want a mocking solution designed specifically for the language rather than adapting Java-focused tools. The library supports multiple deployment contexts including JVM unit tests, Android unit tests, and instrumented Android tests through separate artifact variants. It integrates with Spring Boot and Quarkus through dedicated support libraries. Developers should be aware of known limitations: inline functions cannot be mocked, PowerMock requires workarounds to run alongside MockK, and certain JDK versions introduce warnings or access exceptions when using spies and static mocking.
The project maintains a substantial base of real-world adopters, as evidenced by the fact that nearly all open issues originate from outside users rather than the core team. However, responses to issues and pull requests frequently take weeks or longer. Work in the issue tracker centers on bug fixes, important issues, and enhancement requests.