CheckOps home

Tools directory

M

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Kotlin-first DSL: every, verify and friends read naturally.
  2. Coroutines: coEvery and coVerify for suspend functions.
  3. Final classes and objects: Mock objects, companions, statics and extensions.
  4. Capturing and spies: Slots, matchers and spyk.

Pros

  1. Free to use: Open source under the Apache-2.0 licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 10 November 2026.
  3. Community: About 5,800 GitHub stars.

Cons

  1. Kotlin-centric: Java codebases are usually better served by Mockito.
  2. Over-mocking risk: Static and object mocking can hide design problems.
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.

  1. Kotlin and Android teams that need idiomatic mocks, including coroutines.
  2. 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.