kotlin-testing

Write Kotlin tests using Kotest specs, MockK mocking, coroutine testing, and Kover coverage.

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/JohnRebellion/.claude-public --skill kotlin-testing-johnrebellion
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-testing
Source: https://github.com/JohnRebellion/.claude-public/tree/main/claude/skills/kotlin-testing
Command: npx skills add https://github.com/JohnRebellion/.claude-public --skill kotlin-testing-johnrebellion

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable Kotlin tests requires choosing spec styles, mocking frameworks, coroutine test utilities, and coverage tooling, and this Skill provides ready-to-use patterns for all of them following a TDD workflow. ## Core Features & Use Cases - Kotest Spec Styles: Runnable examples for StringSpec, FunSpec, BehaviorSpec, and DescribeSpec with matchers and custom matcher creation. - MockK and Coroutine Testing: Patterns for mocking dependencies, capturing arguments, testing suspend functions with runTest, and testing Flows with TestDispatcher. - Property-Based and Data-Driven Testing: Kotest property testing with custom Arb generators and withData table-driven tests. - Kover Coverage and CI: Gradle Kover configuration with coverage thresholds, plus GitHub Actions integration. - Use Case: When adding a new Kotlin service class, follow the RED-GREEN-REFACTOR walkthrough to write a failing Kotest spec, mock repositories with MockK, implement the code, and verify 80%+ coverage with koverVerify. ## Quick Start Ask the assistant to write Kotest tests with MockK mocks for a specific Kotlin class following the TDD workflow.

Frequently Asked Questions about kotlin-testing

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

FAQPage Schema
How do I write Kotlin tests with Kotest and MockK?▼

Create a Kotest spec such as FunSpec, declare mocks with mockk<YourInterface>(), stub calls with every or coEvery for suspend functions, and assert results with Kotest matchers like shouldBe. Verify interactions using verify or coVerify.

How to test Kotlin coroutines and suspend functions?▼

Wrap test bodies in runTest from kotlinx-coroutines-test, use coEvery and coVerify for suspend function mocking, and control virtual time with advanceTimeBy instead of Thread.sleep. StandardTestDispatcher gives controlled execution of launched coroutines.

Which Kotest spec style should I use?▼

StringSpec suits simple one-line tests, FunSpec mirrors JUnit-style test methods, BehaviorSpec supports BDD Given/When/Then structure, and DescribeSpec matches RSpec nesting. Pick one style and apply it consistently across the project.

How do I enforce code coverage in Kotlin with Kover?▼

Apply the org.jetbrains.kotlinx.kover Gradle plugin, configure a verify rule with minBound(80) to fail builds below 80 percent coverage, and run ./gradlew koverVerify in CI. Generate reports with koverHtmlReport or koverXmlReport.

What are the limitations of mocking in Kotlin tests?▼

Data classes should not be mocked; use real instances instead. MockK handles final classes and suspend functions, but testing private functions directly is discouraged since tests should verify behavior through public APIs.