kotlin-testing

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill kotlin-testing-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-testing
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/kotlin-testing
Command: npx skills add https://github.com/Femad-6/my-skills --skill kotlin-testing-femad-6

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, which is time-consuming to set up correctly from scratch. ## Core Features & Use Cases - Kotest Spec Patterns: Runnable examples for StringSpec, FunSpec, BehaviorSpec, and DescribeSpec with matchers and custom matcher creation. - MockK and Coroutine Testing: Mocking with coEvery/coVerify, argument capture, spies, runTest, Flow testing, and TestDispatcher control. - 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 80% verification thresholds and GitHub Actions integration. - Use Case: When adding tests to a Kotlin service class, follow the RED-GREEN-REFACTOR walkthrough to write a failing Kotest spec, mock dependencies with MockK, implement the code, and verify coverage with ./gradlew 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<YourType>(), stub calls with every or coEvery for suspend functions, and assert with Kotest matchers like shouldBe. Verify interactions using verify or coVerify after exercising the code under test.

How to test Kotlin coroutines and suspend functions?

Wrap test bodies in runTest from kotlinx-coroutines-test, which provides a controlled virtual-time scheduler. Use advanceTimeBy or advanceUntilIdle instead of Thread.sleep, and use coEvery/coVerify from MockK for suspending dependencies.

Which Kotest spec style should I use?

StringSpec suits simple one-line assertions, FunSpec mirrors JUnit-style named tests, 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 a Kotlin Gradle project?

Apply the org.jetbrains.kotlinx.kover plugin, configure a verify rule with minBound(80), and run ./gradlew koverVerify to fail the build below the threshold. Generate reports with koverHtmlReport or koverXmlReport for CI upload.

Can I test Ktor server routes without starting a real server?

Yes, use Ktor's testApplication block, call application { configureRouting() } to install your modules, then make requests with the built-in client and assert on response status and deserialized bodies.

When should I use property-based testing in Kotlin?

Use Kotest property testing with forAll or checkAll for pure functions where invariants hold across many inputs, such as serialization roundtrips or idempotent operations. Define custom Arb generators for domain types like User or Money.