Mockito for Android tests
Sets up Mockito and its Kotlin DSL in Android unit tests with the right matchers, so your mocks behave.
Claude's review
7/10 Concrete Mockito and mockito-kotlin setup, matcher rules and pitfalls for Android tests.
We asked Claude the question you would ask: would I be glad I installed this? We only sell skills it rates 7 or higher.
In detail
Use this skill to wire Mockito (the dominant Android mocking framework, exclusively used by androidx itself) into a JVM unit-test suite. Covers `org.mockito:mockito-core:5.x` plus the `org.mockito.kotlin:mockito-kotlin:5.x` Kotlin DSL — `mock<T>()`, `whenever`, `argumentCaptor<T>()`, `any()` / `anyOrNull()` / `eq()`, `MockitoJUnit.rule()` vs `MockitoAnnotations.openMocks(this)` lifecycle, the inline mock-maker for Kotlin final classes (`mock-maker-inline` plugin file), `@SdkSuppress(minSdkVersion = 28)` for instrumented final-class mocks, and the suspend-stubbing escape hatch via `runBlocking`. Use when the user mentions `whenever`, `Cannot mock final class`, `InvalidUseOfMatchersException`, `@Mock null`, `MockitoJUnitRunner`, `argumentCaptor`, `mock-maker-inline`, or asks how to mock with mockito-kotlin.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: mocking-with-mockito
description: Use this skill to wire Mockito (the dominant Android mocking framework, exclusively used by androidx itself) into a JVM unit-test suite. Covers `org.mockito:mockito-core:5.x` plus the `org.mockito.kotlin:mockito-kotlin:5.x` Kotlin DSL — `mock<T>()`, `whenever`, `argumentCaptor<T>()`, `any()` / `anyOrNull()` / `eq()`, `MockitoJUnit.rule()` vs `MockitoAnnotations.openMocks(this)` lifecycle, the inline mock-maker for Kotlin final classes (`mock-maker-inline` plugin file), `@SdkSuppress(minSdkVersion = 28)` for instrumented final-class mocks, and the suspend-stubbing escape hatch via `runBlocking`. Use when the user mentions `whenever`, `Cannot mock final class`, `InvalidUseOfMatchersException`, `@Mock null`, `MockitoJUnitRunner`, `argumentCaptor`, `mock-maker-inline`, or asks how to mock with mockito-kotlin.
license: Apache-2.0. See LICENSE for complete terms.
metadata:
author: Jaewoong Eum (skydoves)
keywords:
- android-testing
- mockito
- mockito-kotlin
- jvm-unit-tests
- mock-maker-inline
- argumentCaptor
- whenever
- MockitoJUnit-rule
- final-class-mocking
- openMocks
---
# 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
- The user wants `coEvery` / `coVerify` for suspend functions, deep singleton mocking via `mockkObject`, or static mocking via `mockkStatic` — use `../mocking-with-mockk/SKILL.md`.
- The user is choosing between fakes and mocks at the design level — use `../../../fundamentals/doubles/picking-test-doubles/SKILL.md`. Per /test-doubles, fakes are preferred over mocks for behaviour-heavy collaborators.
- The runner / Gradle matrix isn't set up yet — start with `../../runner/configuring-junit4-on-android/SKILL.md`.
- The user wants `runTest`-aware testing for coroutines — see `../../coroutines/testing-coroutines-with-runtest/SKILL.md`.
...From skydoves's repository, Apache-2.0 licence.
Related skills
-
Checked
Android Gradle Plugin upgrade
Moves Kotlin Multiplatform projects to Android Gradle Plugin 9 and fixes the build failures it causes.
8/101 credit -
Checked
CocoaPods to SwiftPM
Moves Kotlin Multiplatform projects from CocoaPods to Swift Package Manager and updates the Xcode project.
8/101 credit -
Checked
Kotlin Native build speed
Diagnoses and fixes slow Kotlin/Native iOS builds in Kotlin Multiplatform projects, both locally and on CI.
8/101 credit -
Checked
SwiftUI Liquid Glass
Adds and reviews Liquid Glass in SwiftUI apps for iOS 26, avoiding pitfalls with bars, buttons and scrolling.
8/101 credit -
Checked
Compose Multiplatform UI
Builds one shared Compose UI in Kotlin for Android, iOS and desktop, so you write your screens once.
7/101 credit -
Checked
SwiftUI Mac app rules
Writes and debugs Swift 6 and SwiftUI code for Mac apps, fixing concurrency, state and common compiler errors.
7/101 credit