kotlin-testing

Provide Kotlin testing patterns for Kotest, MockK, and coroutines.

1|Updated Apr 7, 2026
One-click install
npx skills add https://github.com/riftzen-bit/gemini-setup --skill kotlin-testing-riftzen-bit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-testing
Source: https://github.com/riftzen-bit/gemini-setup/tree/main/skills/kotlin-testing
Command: npx skills add https://github.com/riftzen-bit/gemini-setup --skill kotlin-testing-riftzen-bit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a comprehensive set of Kotlin testing patterns and examples to reduce flaky tests, speed up TDD workflows, and improve test coverage and maintainability across Kotlin codebases.

Core Features & Use Cases

  • Kotest Spec Examples: Ready-to-use patterns for StringSpec, FunSpec, BehaviorSpec, and DescribeSpec to match different testing styles.
  • Mocking & Coroutines: MockK examples including coroutine mocking, argument capture, spies, and best practices for suspend functions using runTest and TestDispatcher.
  • Property-Based & Integration Testing: Property testing generators, Ktor testApplication examples, data-driven tests, lifecycle fixtures, and Kover configuration for coverage verification.
  • Use Case: Adopt this Skill when practicing TDD on a Kotlin service that uses coroutines, requires mocking of suspending repositories, and must meet CI coverage gates.

Quick Start

Write a failing Kotest spec for the target function, implement the minimal code to make the test pass, and run ./gradlew test koverHtmlReport to verify behavior and coverage.

Frequently Asked Questions about kotlin-testing

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

FAQPage Schema
How do I test Kotlin suspend functions with MockK and runTest?

To test Kotlin suspend functions with MockK, use the coroutine runTest API alongside TestDispatcher to control virtual time and mock suspending repository calls. This ensures deterministic execution and reliable verification of coroutine behavior without flaky delays.

What is the best way to configure Kover for Gradle coverage verification?

Configuring Kover for Gradle coverage verification involves setting up the Kover plugin and running the koverHtmlReport task to generate reports. You can enforce CI coverage gates by defining verification rules in your Gradle build script to fail builds below thresholds.

How do I write property-based tests in Kotlin using Kotest generators?

Writing property-based tests in Kotest involves using built-in generators to produce random input data and assert that invariants hold across all generated values. This approach catches edge cases that traditional data-driven tests might miss by exploring a wider input space.

Does this Kotlin testing approach work with Ktor testApplication for integration testing?

Yes, this Kotlin testing approach works with Ktor testApplication for integration testing. It provides patterns to configure test environments and validate HTTP endpoints alongside your unit tests, ensuring reliable end-to-end behavior verification for Ktor services.

What are the differences between Kotest StringSpec, FunSpec, BehaviorSpec, and DescribeSpec?

Kotest StringSpec, FunSpec, BehaviorSpec, and DescribeSpec offer different structural styles for organizing tests. StringSpec uses simple strings, FunSpec uses closures, BehaviorSpec follows Given-When-Then, and DescribeSpec uses nested describe blocks to match varied testing preferences.

Why are my Kotlin coroutine tests flaky and how do I control dispatchers?

Kotlin coroutine tests become flaky due to uncontrolled dispatcher scheduling and real-time delays. You can fix this by using runTest with TestDispatcher to control virtual time, ensuring suspend function execution remains deterministic and free of race conditions.