Build high-quality Kotlin tests with Kotest, MockK, coroutines, and coverage.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "kotlin-testing" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/kotlin-testing/SKILL.md 2. Save it as ~/.claude/skills/kotlin-testing/SKILL.md 3. Reload skills and tell me it's ready
Write unit tests for this Kotlin coroutine service using Kotest and MockK. Cover success, failure, and cancellation scenarios, and explain why the test structure is designed this way.
A set of idiomatic Kotlin coroutine unit tests with an explanation of the test design.
I have a piece of Kotlin business logic. Use TDD to list test cases first, then provide a refactored implementation with Kotest tests and necessary MockK examples.
A test plan and test code first, followed by a refactored implementation that passes them.
Design property-based tests for this Kotlin data transformation function, and use Kover-oriented advice to improve coverage and identify missing edge cases.
Property-based test examples, key edge-case analysis, and actionable coverage improvement suggestions.
Comprehensive Kotlin testing patterns for writing reliable, maintainable tests following TDD methodology with Kotest and MockK.
./gradlew koverHtmlReport and verify 80%+ coverageThe following sections contain detailed, runnable examples for each testing pattern:
RED -> Write a failing test first
GREEN -> Write minimal code to pass the test
REFACTOR -> Improve code while keeping tests green
REPEAT -> Continue with next requirement
// Step 1: Define the interface/signature
// EmailValidator.kt
package com.example.validator
fun validateEmail(email: String): Result<String> {
TODO("not implemented")
}
// Step 2: Write failing test (RED)
// EmailValidatorTest.kt
package com.example.validator
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.result.shouldBeFailure
import io.kotest.matchers.result.shouldBeSuccess
class EmailValidatorTest : StringSpec({
"valid email returns success" {
validateEmail("[email protected]").shouldBeSuccess("[email protected]")
}
"empty email returns failure" {
validateEmail("").shouldBeFailure()
}
"email without @ returns failure" {
validateEmail("userexample.com").shouldBeFailure()
}
})
// Step 3: Run tests - verify FAIL
// $ ./gradlew test
// EmailValidatorTest > valid email returns success FAILED
// kotlin.NotImplementedError: An operation is not implemented
// Step 4: Implement minimal code (GREEN)
fun validateEmail(email: String): Result<String> {
if (email.isBlank()) return Result.failure(IllegalArgumentException("Email cannot be blank"))
if ('@' !in email) return Result.failure(IllegalArgumentException("Email must contain @"))
val regex = Regex("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")
if (!regex.matches(email)) return Result.failure(IllegalArgumentException("Invalid email format"))
return Result.success(email)
}
// Step 5: Run tests - verify PASS
// $ ./gradlew test
// EmailValidatorTest > valid email returns success PASSED
// EmailValidatorTest > empty email returns failure PASSED
// EmailValidatorTest > email without @ returns failure PASSED
// Step 6: Refactor if needed, verify tests still pass
class CalculatorTest : StringSpec({
"add two positive numbers" {
Calculator.add(2, 3) shouldBe 5
}
"add negative numbers" {
Calculator.add(-1, -2) shouldBe -3
}
"add zero" {
Calculator.add(0, 5) shouldBe 5
}
})
…
Handle returns, refunds, fraud checks, and warranty claim decisions efficiently.
Use Bun for runtime, bundling, testing, packages, and Node migration decisions.
Use the correct Ethereum Keccak-256 hashing in Node.js and TypeScript.
Apply Nuxt 4 patterns for SSR safety, performance, and data fetching.
Generate images, videos, and audio with one unified AI media workflow.
Design Quarkus 3 backend patterns for messaging, APIs, data, and async workflows.
Learn Rust testing patterns and TDD to improve code quality and reliability.
Apply idiomatic Kotlin patterns to build robust, efficient, maintainable applications.
Learn practical Kotlin Coroutines and Flow patterns for Android and KMP.
Build robust Python test suites with pytest, TDD, mocking, and coverage.
Write idiomatic Go tests, benchmarks, fuzz tests, and improve coverage.
Learn practical Kotlin Ktor server patterns for building and testing backend apps.