CheckOps
MockK
MockK is an Apache-2.0 mocking library built for Kotlin, supporting final classes, objects, coroutines, extension functions and top-level functions with a concise DSL.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
MockK is a mocking library designed specifically for Kotlin. Kotlin classes are final by default and the language has features such as objects, companion objects, extension functions and coroutines that Java-oriented mocking libraries handle awkwardly. MockK supports them directly with an idiomatic DSL.
You create mocks with mockk<T>() (strict by default) or mockk<T>(relaxed = true), define behaviour with every { ... } returns ..., and verify with verify { ... }. Suspend functions use coEvery and coVerify. Argument matchers and capturing (slot<T>()) are built in, spyk creates spies, mockkObject and mockkStatic mock singletons and top-level or extension functions, and annotations (@MockK, @InjectMockKs) integrate with JUnit 4 and 5. MockK also supports Android instrumented tests. Version 1.14.12 was released on 7 November 2026.
The source code is at mockk/mockk on GitHub under the Apache-2.0 licence, with about 5,800 stars; the most recent commit was on 10 November 2026.
Features
- Kotlin-first DSL:
every,verifyand friends read naturally. - Coroutines:
coEveryandcoVerifyfor suspend functions. - Final classes and objects: Mock objects, companions, statics and extensions.
- Capturing and spies: Slots, matchers and
spyk.
Pros
- Free to use: Open source under the Apache-2.0 licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 10 November 2026.
- Community: About 5,800 GitHub stars.
Cons
- Kotlin-centric: Java codebases are usually better served by Mockito.
- Over-mocking risk: Static and object mocking can hide design problems.
Usage and Links (Example)
testImplementation("io.mockk:mockk:<version>")
class CheckoutServiceTest {
private val payments = mockk<PaymentGateway>()
private val service = CheckoutService(payments)
@Test
fun chargesCard() = runTest {
coEvery { payments.charge(any(), 100) } returns Result.success("tx-1")
service.checkout(cart(total = 100))
coVerify(exactly = 1) { payments.charge(any(), 100) }
}
}
Resources:
Pricing
MockK is free and open source under the Apache-2.0 licence.
Recommended for?
- Kotlin and Android teams that need idiomatic mocks, including coroutines.
- Codebases using Kotlin objects and extension functions.
Conclusion
MockK is the standard mocking library for Kotlin, handling the language’s features far more naturally than Java-first alternatives.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with MockK side by side.
MMockitoMockito is the MIT-licensed, most popular mocking framework for Java, used to create mocks, stubs and spies with a clean API; Mockito 5 uses the inline mock maker by default and requires Java 11.Compare with MockK
KKotestKotest is an Apache-2.0 Kotlin multiplatform test framework with multiple testing styles, a large assertions library and built-in property-based testing.Compare with MockK
JJUnit 5JUnit 5 is the current JUnit for Java and the JVM: Jupiter for new tests, Platform to launch them, Vintage to run JUnit 4.Compare with MockK
RRobolectricRobolectric is an MIT-licensed Android unit testing framework that runs tests in a simulated Android environment inside the JVM, routinely 10x faster than cold-started emulators, supporting 14 Android versions from API 24 to 37.Compare with MockK
SSpock FrameworkSpock is an Apache-2.0 BDD-style testing and specification framework for Java and Groovy applications, with given/when/then blocks, powerful data-driven tests and built-in mocking, running on the JUnit Platform.Compare with MockK
AAssertJAssertJ is an Apache-2.0 fluent assertions library for Java, with rich, discoverable assertions for core types, collections, exceptions, dates and more, plus soft assertions and custom assertion generation.Compare with MockK