mocking-with-mockito

Configure Mockito and mockito-kotlin for Kotlin Android unit tests.

Updated Jul 20, 2026
One-click install
npx skills add https://github.com/trancee/MeshLink-template --skill mocking-with-mockito-trancee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mocking-with-mockito
Source: https://github.com/trancee/MeshLink-template/tree/main/.agents/skills/android-testing-skills/jvm-tests/mocking/mocking-with-mockito
Command: npx skills add https://github.com/trancee/MeshLink-template --skill mocking-with-mockito-trancee

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires org.mockito:mockito-core, org.mockito.kotlin:mockito-kotlin.

What problem does it solve?

This skill resolves the complexity of setting up robust unit tests in Kotlin Android projects, specifically addressing the friction between Mockito's Java-centric design and Kotlin's strict type system and final-class defaults.

Core Features & Use Cases

  • Kotlin-First DSL: Provides idiomatic wrappers for mocking, verification, and argument capturing using the mockito-kotlin library.
  • Final Class Support: Configures the inline mock-maker to allow mocking of Kotlin final classes without boilerplate.
  • Lifecycle Management: Standardizes the use of MockitoJUnit rules and AutoCloseable resources to prevent memory leaks and test pollution.

Quick Start

Use the mocking-with-mockito skill to configure your test suite and stub a repository dependency in your ViewModel test.

Frequently Asked Questions about mocking-with-mockito

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock final classes in Kotlin Android unit tests?

To mock final classes in Kotlin Android unit tests, configure the mock-maker-inline extension to bypass Kotlin's final-class restrictions. This setup allows the Mockito framework to directly mock final classes and stub their methods without requiring boilerplate code.

Why does Mockito strict stubbing fail when verifying suspend functions?

Strict stubbing fails verifying suspend functions when standard Java-centric Mockito wrappers cannot handle Kotlin coroutine types. Integrating the mockito-kotlin DSL provides idiomatic wrappers to properly stub suspend functions and verify interaction patterns in complex Android components.

Does mockito-kotlin support null-safe argument matching for JVM unit tests?

Yes, mockito-kotlin supports null-safe argument matching for JVM unit tests. It provides idiomatic wrappers that align Mockito's Java-centric design with Kotlin's strict type system, ensuring null-safe argument capture and preventing NullPointerExceptions during verification.

What is the best way to prevent memory leaks when stubbing repository dependencies?

The best way to prevent memory leaks when stubbing repository dependencies is standardizing the test lifecycle with MockitoJUnit rules and AutoCloseable resources. Proper lifecycle management ensures mocks are automatically released after each test, preventing test pollution and memory leaks.

When do I need an argument captor for Android component verification?

You need an argument captor for Android component verification when you must assert that specific complex data objects were passed to mocked dependencies. Using the mockito-kotlin DSL, you can safely capture and assert arguments without strict stubbing errors, validating complex interaction patterns.