mockk-testing-patterns

Guide MockK-based AniTrend tests with correct source sets and coroutine primitives.

51|6|Updated Mar 10, 2019
One-click install
npx skills add https://github.com/AniTrend/anitrend-v2 --skill mockk-testing-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mockk-testing-patterns
Source: https://github.com/AniTrend/anitrend-v2/tree/main/.agents/skills/mockk-testing-patterns
Command: npx skills add https://github.com/AniTrend/anitrend-v2 --skill mockk-testing-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

It prevents flaky or incorrect unit/instrumentation tests by guiding you to use the right MockK primitives (every/coEvery/verify/coVerify), the correct test source set, and AniTrend’s existing Koin + coroutine + Turbine patterns.

Core Features & Use Cases

  • Correctly choose test vs androidTest based on whether Android runtime behavior is required.
  • Use coroutine-aware stubbing and verification via coEvery/coVerify for suspend paths and every/verify for regular calls.
  • Assert Flow/DataState emissions with Turbine, focusing on observable contract instead of internal implementation.
  • Validate Koin DI graphs using MockProviderRule.create { mockk() } without inventing custom wiring.
  • Keep mocks minimal and meaningful, mocking collaborators (gateways/DAOs/interactors) rather than value objects or the subject under test.
  • Review and completion guardrails to avoid redundant dependencies and brittle over-verification.

Quick Start

Use mockk-testing-patterns when you need to stub or verify suspend and non-suspend collaborators in an AniTrend unit test, including Flow assertions with Turbine, and follow the rule to keep MockK dependencies managed by buildSrc.

Frequently Asked Questions about mockk-testing-patterns

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

FAQPage Schema
How do I stub suspend functions with MockK in Kotlin unit tests?

Stub suspend functions with MockK using coEvery for setup and coVerify for confirmation, reserving every and verify strictly for non-suspend calls. This ensures coroutine-aware stubbing and verification in your Kotlin unit tests.

What is the best way to assert Flow emissions in Android testing?

Assert Flow emissions in Android testing using Turbine to validate the observable contract of DataState streams. This focuses on emission sequences rather than internal implementation details, preventing flaky coroutine tests.

How do I validate Koin module graphs without manual mock wiring?

Validate Koin module graphs without manual wiring by applying MockProviderRule with mockk to inject mock collaborators. This verifies dependency injection setup reliably while keeping mocks minimal and meaningful.

When do I need androidTest versus test for MockK instrumentation tests?

Choose androidTest over test when your MockK tests require actual Android runtime behavior integration. Use the standard test source set for pure unit tests that do not depend on the Android framework environment.

Why does my MockK unit test fail when mocking value objects?

MockK unit tests fail when mocking value objects because you should mock collaborators like gateways or DAOs instead. Mocking data classes or the subject under test creates brittle tests and redundant verification issues.