kotlin-testing

Write Kotlin tests with Kotest, MockK, coroutine testing, and Kover coverage following TDD.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-testing-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-testing
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/kotlin-testing
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-testing-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable Kotlin tests requires choosing spec styles, mocking suspend functions correctly, testing coroutines and Flows, and enforcing coverage thresholds, which is error-prone without established patterns. ## Core Features & Use Cases - Kotest Spec Styles: Runnable examples for StringSpec, FunSpec, BehaviorSpec, and DescribeSpec with expressive matchers and custom matcher creation. - MockK and Coroutine Testing: Patterns for mocking dependencies, capturing arguments, testing suspend functions with runTest, and verifying Flow emissions with TestDispatcher. - Property-Based and Data-Driven Testing: Kotest property testing with custom Arb generators and withData tables for parameterized cases. - Kover Coverage and CI: Gradle Kover configuration with 80% verification rules plus GitHub Actions integration. - Use Case: When adding a new EmailValidator to a Kotlin service, follow the RED-GREEN-REFACTOR walkthrough to write a failing StringSpec first, implement minimal code, then verify coverage with ./gradlew koverHtmlReport. ## Quick Start Write a Kotest test for my Kotlin UserService class using MockK to mock the repository and 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?▼

Choose a Kotest spec style like FunSpec, create mocks with mockk<Repository>(), stub calls with every or coEvery for suspend functions, and assert with 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 from MockK for suspend mocks, and control virtual time with advanceTimeBy instead of Thread.sleep. TestDispatcher gives controlled execution of launched coroutines.

Which Kotest spec style should I use for my tests?▼

StringSpec suits simple assertions, FunSpec mirrors JUnit-style tests, BehaviorSpec fits BDD Given/When/Then scenarios, and DescribeSpec matches RSpec-style nesting. Pick one style and apply it consistently across the project.

Does Kotest support property-based testing in Kotlin?▼

Yes, Kotest property testing uses forAll and checkAll with Arb generators to verify invariants across random inputs. Build custom generators with Arb.bind to produce domain objects like User or Money for roundtrip and idempotency checks.

How do I enforce code coverage thresholds with Kover?▼

Apply the kotlinx.kover Gradle plugin and add a verify rule with minBound(80) in the kover reports block. Run ./gradlew koverVerify to fail the build below the threshold and koverHtmlReport to inspect results.

Why should I avoid mocking data classes in Kotlin tests?▼

Data classes are simple value holders, so use real instances as test fixtures instead of mocks. Mocking them adds fragility without benefit; reserve MockK for services, repositories, and other behavioral dependencies.