kotlin-testing

Write Kotlin unit tests with MockK and Kotest following TDD cycles.

2|Updated Apr 7, 2026
One-click install
npx skills add https://github.com/Zenobia000/ai-brainstorming --skill kotlin-testing-zenobia000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-testing
Source: https://github.com/Zenobia000/ai-brainstorming/tree/main/.claude/custom-rule%26skill/skills/kotlin-testing
Command: npx skills add https://github.com/Zenobia000/ai-brainstorming --skill kotlin-testing-zenobia000

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the common pain of writing inconsistent, hard-to-maintain Kotlin tests that fail to follow TDD best practices, and fills gaps in coverage for coroutine, property-based, and integration testing scenarios.

Core Features & Use Cases

  • TDD-aligned testing workflow: Full RED/GREEN/REFACTOR cycle guidance for Kotlin projects using Kotest, with step-by-step examples.
  • Comprehensive mocking and coroutine support: MockK setup for unit tests, including suspend function mocking, argument capture, and flow testing with runTest.
  • Use case: A Kotlin backend developer building a user service can use this Skill to write unit tests for suspend repository calls, mock dependencies with MockK, and verify 80%+ Kover coverage for their code.

Quick Start

Use the kotlin-testing skill to write a passing unit test for your Kotlin suspend function that fetches user data from a repository, following the TDD RED/GREEN/REFACTOR cycle.

Frequently Asked Questions about kotlin-testing

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

FAQPage Schema
How do I write unit tests for Kotlin suspend functions using MockK and Kotest?

To write unit tests for Kotlin suspend functions, you use MockK to mock repository calls and runTest to handle coroutine suspension. This approach enables consistent, maintainable testing aligned with TDD best practices.

What's the best way to mock Kotlin coroutine flows in TDD?

The best way to mock Kotlin coroutine flows in TDD is using MockK for flow mocking and runTest for coroutine execution. This ensures reliable testing of suspend functions and flow emissions within the RED/GREEN/REFACTOR cycle.

Does Kover work with Kotest for validating test coverage in Kotlin?

Yes, Kover works with Kotest to validate test coverage in Kotlin projects. It satisfies requirements for coverage validation by measuring executed code paths, helping ensure 80%+ coverage for backend and mobile applications.

Can I use TDD practices for Kotlin multiplatform testing?

Yes, you can apply TDD practices for Kotlin multiplatform testing. This approach supports backend, mobile, and multiplatform projects requiring tests for property-based logic, suspend functions, and Ktor API endpoints.

How to set up a RED/GREEN/REFACTOR cycle for Kotlin Ktor API endpoint testing?

To set up a RED/GREEN/REFACTOR cycle for Ktor API endpoint testing, follow step-by-step TDD guidance using Kotest. Write failing tests first, implement code to pass them, then refactor while maintaining MockK dependency isolation and Kover coverage validation.

Why does my Kotlin test fail when mocking suspend functions with MockK?

Kotlin tests fail when mocking suspend functions with MockK if coroutine testing setup is incorrect. Use runTest from kotlinx-coroutines-test to properly execute suspending code blocks and verify mocked suspend repository calls.