kotlin-testing

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill kotlin-testing-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-testing
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/kotlin-testing
Command: npx skills add https://github.com/ibytechaos/claude --skill kotlin-testing-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing idiomatic, maintainable Kotlin tests requires choosing the right spec style, mocking framework, and coroutine test utilities, and developers often struggle to apply TDD consistently across Kotlin projects. ## Core Features & Use Cases - Kotest Spec Styles: Provides runnable examples for StringSpec, FunSpec, BehaviorSpec, and DescribeSpec with matchers and custom matcher creation. - MockK and Coroutine Testing: Covers basic mocking, coEvery/coVerify for suspend functions, argument capture, spies, runTest, Flow testing, and TestDispatcher control. - Property-Based and Data-Driven Testing: Includes Kotest property testing with custom Arb generators and withData table-driven tests. - Use Case: When adding a new UserService class to a Ktor backend, follow the RED-GREEN-REFACTOR walkthrough to write a failing FunSpec test with MockK-stubbed repository calls, implement the code, then verify 80%+ coverage with ./gradlew koverVerify. ## Quick Start Ask the assistant to write a Kotest test 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?

Choose a Kotest spec style like FunSpec, create mocks with mockk<YourInterface>(), stub calls with every or coEvery for suspend functions, and assert 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 and use coEvery/coVerify in MockK for suspend functions. Control virtual time with advanceTimeBy and StandardTestDispatcher instead of Thread.sleep.

Which Kotest spec style should I use?

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

How do I measure Kotlin test coverage with Kover?

Apply the org.jetbrains.kotlinx.kover Gradle plugin, then run ./gradlew koverHtmlReport for reports and koverVerify to enforce thresholds. Configure minBound(80) to fail builds below 80% coverage.

Can I test Ktor routes without starting a server?

Yes, use Ktor's testApplication block to configure routing and serialization in-memory, then call client.get or client.post and assert on response status and deserialized bodies.

What should I avoid when writing Kotlin tests?

Avoid mocking data classes, mixing multiple test frameworks, using Thread.sleep in coroutine tests, skipping the RED phase of TDD, and testing private functions directly. Use real instances for data classes and advanceTimeBy for delays.