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 classfrom Mockito 4.x and needs themock-maker-inlineconfiguration. - The user reports
InvalidUseOfMatchersExceptionfrom mixing raw values withany()/eq(). - The user is wrestling with the
whenkeyword clash in Kotlin (`when`(mock.foo())) and wants thewheneverDSL. - The user wants
argumentCaptor<T>()withfirstValue/lastValue/allValuesinstead ofArgumentCaptor.forClass(...). - The user is migrating from
MockitoAnnotations.initMocks(this)toopenMocks(this)or theMockitoJUnit.rule()approach. - The user is mocking a
finalclass on an instrumented test on API < 28.