mocking-with-mockito

Installation
SKILL.md

Mocking with Mockito — The androidx-Native Mocking Stack

Mockito is the mocking framework androidx itself uses — 400+ test files import org.mockito across the AOSP checkout, while io.mockk returns zero hits. New Android code that wants to "match what Google does" picks Mockito + the mockito-kotlin Kotlin DSL. This skill documents the exact dependency matrix, the three setup styles, the Kotlin DSL surface, and the inline-mock-maker plumbing required for Kotlin final classes.

When to use this skill

  • The user is starting a new test suite in a Kotlin Android module and asks "what mocking library should I use".
  • The user reports Cannot mock/spy class … final class from Mockito 4.x and needs the mock-maker-inline configuration.
  • The user reports InvalidUseOfMatchersException from mixing raw values with any() / eq().
  • The user is wrestling with the when keyword clash in Kotlin (`when`(mock.foo())) and wants the whenever DSL.
  • The user wants argumentCaptor<T>() with firstValue / lastValue / allValues instead of ArgumentCaptor.forClass(...).
  • The user is migrating from MockitoAnnotations.initMocks(this) to openMocks(this) or the MockitoJUnit.rule() approach.
  • The user is mocking a final class on an instrumented test on API < 28.

When NOT to use this skill

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