mocking-with-mockk

Installation
SKILL.md

Mocking with MockK — The Kotlin-First Mocking Stack

MockK is the Kotlin-first alternative to Mockito. Its headline wins are native suspend support (coEvery / coVerify with no runBlocking dance), first-class singleton / object / static / constructor mocking, and Kotlin-native syntax (every { … } returns x). The trade-off: androidx itself does NOT use MockK (a grep -r "io.mockk" over the AOSP checkout returns zero hits — see ../mocking-with-mockito/SKILL.md for the dominant pattern). New Kotlin code outside Google often picks MockK; new Kotlin code inside Google or matching AOSP conventions picks Mockito. Both are valid.

When to use this skill

  • The codebase is Kotlin-only and dominated by suspend functions / coroutines, and the user wants ergonomic suspend stubbing.
  • The user needs to mock a Kotlin object (singleton), companion object, top-level function (Kt-suffixed file), or every newly-constructed instance of a class.
  • The user wants strict-by-default verification with the option to opt out per-mock via relaxed = true / relaxUnitFun = true.
  • The user wants slot<T>() capture with slot.captured (cleaner than Mockito's ArgumentCaptor).
  • The user is writing tests for viewModelScope, Flow collectors, LaunchedEffect-style suspend collaborators.

When NOT to use this skill

Installs
38
GitHub Stars
319
First Seen
May 16, 2026
mocking-with-mockk — skydoves/android-testing-skills