mocking-with-mockk

Mocks Kotlin suspend functions, objects, and static methods in JVM unit tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the complexity of testing Kotlin code that relies on coroutines, singletons, static methods, or complex object construction, providing a native and ergonomic alternative to traditional Java-based mocking frameworks.

Core Features & Use Cases

  • Native Coroutine Support: Use coEvery and coVerify to test suspend functions without the need for complex runBlocking wrappers.
  • Advanced Mocking: Easily mock Kotlin objects, companion objects, top-level functions, and constructors with global hook management.
  • Use Case: When testing a ViewModel that interacts with a repository using Flow or suspend functions, this skill allows you to precisely stub network responses and verify interaction sequences with minimal boilerplate.

Quick Start

Use the mocking-with-mockk skill to configure a test class that mocks a repository singleton and verifies a specific suspend function call.

Frequently Asked Questions about mocking-with-mockk

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

FAQPage Schema
How do I mock suspend functions in Kotlin coroutines without using runBlocking wrappers?

Mocking Kotlin objects and companion objects in unit tests is done using advanced mocking frameworks that manage global hooks to intercept static methods and singleton interactions natively.

What is the best way to test a ViewModel that interacts with a repository using Flow?

The best way to test a ViewModel interacting with a repository using Flow is to mock the repository singleton, precisely stub network responses, and verify suspend function interaction sequences with minimal boilerplate.

Can I mock top-level functions and constructors in Kotlin Multiplatform projects?

Yes, you can mock top-level functions and constructors in Kotlin Multiplatform projects by applying global hook management to intercept and verify complex object construction and static method calls.

Does MockK support strict verification of interaction patterns for Android testing?

Yes, MockK supports strict verification of interaction patterns for Android testing, ensuring proper lifecycle management of global mocking hooks during complex asynchronous code verification.

Why use a Kotlin-first mocking framework instead of traditional Java-based mocking tools?

Use a Kotlin-first mocking framework instead of traditional Java-based tools to natively handle Kotlin-specific constructs like coroutines, objects, and companion objects without complex boilerplate or wrappers.