kotlin-testing
Skill0 starsChanged 49 days agoMITView on GitHub
Write and improve Kotlin tests with Kotest, MockK, coroutine test tools, property tests, Kover, and the red-green-refactor TDD cycle. Use for new Kotlin code, missing tests, test bugs, slow or flaky tests, and coverage setup.
13 other projects use a version of this.
Adopted by
Most recently taken up by
- Rojios/everything-claude-codetheir own version, first seen Nov 8, 2026
- renepf/claude-skillstheir own version, first seen Oct 25, 2026
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
- full-stack-skills/kotlin-skillstheir own version, first seen Oct 13, 2026
- gongyijie85/dsh-ecctheir own version, first seen Oct 13, 2026
- MohamedEssam0-0/claude-skillstheir own version, first seen Oct 11, 2026
Used with
Projects with it also use nuxt4-patterns, agent-payment-x402 and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
loulanyueSkillnuxt4-patterns
Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.
Also in 10 projects that use this
TironFoxSkillagent-payment-x402
Add x402 payment execution to AI agents — per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents need to pay for APIs, services, or other agents.
Also in 6 projects that use this
TironFoxSkillopenclaw-persona-forge
为 OpenClaw AI Agent 锻造完整的龙虾灵魂方案。根据用户偏好或随机抽卡, 输出身份定位、灵魂描述(SOUL.md)、角色化底线规则、名字和头像生图提示词。 如当前环境提供已审核的生图 skill,可自动生成统一风格头像图片。 当用户需要创建、设计或定制 OpenClaw 龙虾灵魂时使用。 不适用于:微调已有 SOUL.md、非 OpenClaw 平台的角色设计、纯工具型无性格 Agent。 触发词:龙虾灵魂、虾魂、OpenClaw 灵魂、养虾灵魂、龙虾角色、龙虾定位、 龙虾剧本杀角色、龙虾游戏角色、龙虾 NPC、龙虾性格、龙虾背景故事、 lobster soul、lobster character、抽卡、随机龙虾、龙虾 SOUL、gacha。
Also in 5 projects that use this
RojiosSkilldart-flutter-patterns
Production-ready Dart and Flutter patterns covering null safety, immutable state, async composition, widget architecture, popular state management frameworks (BLoC, Riverpod, Provider), GoRouter navigation, Dio networking, Freezed code generation, and clean architecture.
Also in 6 projects that use this
loulanyueSkillsanta-method
Multi-agent adversarial verification with convergence loop. Two independent review agents must both pass before output ships.
Also in 8 projects that use this
ronmkrSkillquarkus-security
Quarkus Security best practices for authentication, authorization, JWT/OIDC, RBAC, input validation, CSRF, secrets management, and dependency security.
Also in 5 projects that use this
Other versions13 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 13
- loulanyue/awesome-claude-notes★ 272same name
- Fmarzochi/EGC★ 61same name
- gongyijie85/dsh-ecc★ 8same name
- ronmkr/PromptBook★ 2same name
- junimnjw/everything-claude-code★ 1same name
- Rojios/everything-claude-code★ 1same name
- SamuelNDCE/claude-super-skill-library★ 1same name
- TironFox/everything-claude-code★ 1same name
- davidanthonyn/claude-skills★ 0same name
- full-stack-skills/kotlin-skills★ 0same name
3 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this skill into the rules it gives an agent
49 rules. 0 are common, 39 are distinctive, and 10 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
39
Distinctive
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Write small, clear, and stable Kotlin tests.
- Distinctive: line 15
Use this skill when you:
- Distinctive: line 17
Add a Kotlin function or class
- Distinctive: line 18
Add tests to old Kotlin code
- Distinctive: line 20
Test suspend functions or flows
- Distinctive: line 23
Follow test-driven development, or TDD
- Distinctive: line 27
Read the code and its build files.
- Distinctive: line 30
Write one test that fails for the right reason.
- Distinctive: line 31
Run that test and check the failure.
- Distinctive: line 32
Write the least code needed to pass.
- Distinctive: line 33
Run the full test set.
- Distinctive: line 35
Check coverage for missed cases.
- Distinctive: line 37
Do not change build tool or test library unless the task needs it.
- Very specific: line 41
Use StringSpec for short, direct cases.
- Very specific: line 42
Use FunSpec when setup or hooks help.
- Very specific: line 43
Use BehaviorSpec when Given, When, and Then make a rule easier to read.
- Distinctive: line 44
Use a property test when many inputs follow the same rule.
- Distinctive: line 45
Use an integration test when real file, data, or network parts must work together.
- Distinctive: line 47
Test what code does. Do not test private methods on their own.
- Distinctive: line 79
Use clear test names. Each name should state one rule.
- Distinctive: line 83
Use the most exact matcher you can.
- Distinctive: line 107
Check error type and useful error data.
- Very specific: line 140
Use every and verify for normal functions.
- Very specific: line 141
Use coEvery and coVerify for suspend functions.
- Very specific: line 142
Use relaxed = true only when unused calls do not matter.
- Distinctive: line 145
Verify key effects, not every small call.
- Distinctive: line 146
Avoid mocking the class under test.
- Very specific: line 147
Do not hide missing setup with broad any() rules unless the input does not matter.
- Very specific: line 151
Use runTest from kotlinx-coroutines-test.
- Very specific: line 180
Do not use real sleep calls.
- Distinctive: line 188
Test empty, error, and cancel cases.
- Distinctive: line 189
Do not leave jobs running after the test ends.
- Distinctive: line 193
Use property tests for rules that should hold for many values.
- Distinctive: line 211
Keep property tests stable:
- Distinctive: line 214
Add direct tests for key edge cases.
- Distinctive: line 217
Keep each property simple.
- Distinctive: line 218
Do not use random data when a short table of cases is clearer.
- Very specific: line 249
Check that it fails because validateEmail is missing or not done.
- Distinctive: line 269
Run the test again. Then run all tests:
- Distinctive: line 275
Add more rules only when the app needs them.
- Distinctive: line 279
Check cases that fit the code:
- Distinctive: line 297
Use fixed clocks, test data, and random seeds.
- Distinctive: line 301
Use the Kover tasks already set by the project.
- Distinctive: line 316
Run the changed test by itself.
- Distinctive: line 318
Check that no test depends on run order.
- Distinctive: line 319
Check that coroutine jobs end.
- Distinctive: line 320
Check that mocks do not leak between tests.
- Distinctive: line 321
Check key errors and edge cases.
- Distinctive: line 322
Run Kover if coverage is part of the task.
“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Kotlin Testing
Original skill by ECC. Credit ECC in any copy or shared version of this skill.
Write small, clear, and stable Kotlin tests. Use Kotest for tests, MockK for test doubles, coroutine test tools for suspend code, and Kover for coverage.
When to Use
Use this skill when you:
- Add a Kotlin function or class
- Add tests to old Kotlin code
- Fix a broken or flaky test
- Test suspend functions or flows
- Add property tests
- Set up Kover coverage
- Follow test-driven development, or TDD
Main Steps
- Read the code and its build files.
- Find the public result that must be true.
- Pick the smallest useful test type.
- Write one test that fails for the right reason.
- Run that test and check the failure.
- Write the least code needed to pass.
- Run the full test set.
- Clean up the code while tests stay green.
- Check coverage for missed cases.
Do not change build tool or test library unless the task needs it.
Pick the Right Test
- Use
StringSpecfor short, direct cases. - Use
FunSpecwhen setup or hooks help. - Use
BehaviorSpecwhen Given, When, and Then make a rule easier to read. - Use a property test when many inputs follow the same rule.
- Use an integration test when real file, data, or network parts must work together.
Test what code does. Do not test private methods on their own.
TDD Cycle
RED Write one failing test.
GREEN Write the least code that makes it pass.
REFACTOR Make the code clearer.
REPEAT Add the next rule.A RED test must fail because the feature is missing. A test that fails due to bad setup does not count.
Basic Kotest Example
package com.example.math
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
class CalculatorTest : StringSpec({
"adds two numbers" {
Calculator.add(2, 3) shouldBe 5
}
"adds negative numbers" {
Calculator.add(-2, -3) shouldBe -5
}
})Use clear test names. Each name should state one rule.
Matchers
Use the most exact matcher you can.
result shouldBe expected
result shouldNotBe wrongValue
name shouldStartWith "Al"
name shouldContain "lic"
items shouldHaveSize 3
items shouldContain "book"
items.shouldBeEmpty()
value.shouldBeNull()
value.shouldNotBeNull()
value.shouldBeInstanceOf<User>()
count shouldBeGreaterThan 0
shouldThrow<IllegalArgumentException> {
validateAge(-1)
}.message shouldBe "Age must be positive"Check error type and useful error data. Do not only check that some error happened.
For money and decimal values, use the exact type used by the app. For floating point values, use a small allowed gap.
MockK
Mock only code outside the unit under test. Prefer real value objects and small fake classes when they are easy to build.
class UserServiceTest : FunSpec({
val repository = mockk<UserRepository>()
val service = UserService(repository)
beforeTest {
clearMocks(repository)
}
test("returns the saved user") {
val user = User(id = "1", name = "Alice")
every { repository.findById("1") } returns user
service.findUser("1") shouldBe user
verify(exactly = 1) {
repository.findById("1")
}
confirmVerified(repository)
}
})Rules:
- Use
everyandverifyfor normal functions. - Use
coEveryandcoVerifyfor suspend functions. - Use
relaxed = trueonly when unused calls do not matter. - Clear shared mocks before each test.
- Stub every call that affects the result.
- Verify key effects, not every small call.
- Avoid mocking the class under test.
- Do not hide missing setup with broad
any()rules unless the input does not matter.
Coroutine Tests
Use runTest from kotlinx-coroutines-test. It gives safe test scope and virtual time.
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
class AsyncUserServiceTest : FunSpec({
val repository = mockk<UserRepository>()
val service = UserService(repository)
test("loads a user") {
runTest {
val user = User(id = "1", name = "Alice")
coEvery { repository.findById("1") } returns user
service.getUser("1") shouldBe user
coVerify(exactly = 1) {
repository.findById("1")
}
}
}
})Do not use real sleep calls. Use virtual time tools such as advanceTimeBy, runCurrent, or advanceUntilIdle.
Pass a test dispatcher or clock into app code when time or thread choice matters. Restore any changed main dispatcher after the test.
For flows:
- Collect only the values the test needs.
- End collection in the test.
- Test empty, error, and cancel cases.
- Do not leave jobs running after the test ends.
Property Tests
Use property tests for rules that should hold for many values.
import io.kotest.core.spec.style.StringSpec
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.checkAll
import io.kotest.matchers.shouldBe
class MathPropertyTest : StringSpec({
"adding zero keeps the same value" {
checkAll(Arb.int()) { value ->
value + 0 shouldBe value
}
}
})Keep property tests stable:
- Limit data to valid input when needed.
- Add direct tests for key edge cases.
- Include empty, zero, negative, min, and max values when valid.
- Save the random seed when a failure must be run again.
- Keep each property simple.
- Do not use random data when a short table of cases is clearer.
Concrete Usage Example
Task: add an email check.
First, write tests:
class EmailValidatorTest : StringSpec({
"accepts a valid email" {
validateEmail("user@example.com")
.getOrNull() shouldBe "user@example.com"
}
"rejects a blank email" {
validateEmail("").isFailure shouldBe true
}
"rejects an email with no at sign" {
validateEmail("user.example.com").isFailure shouldBe true
}
})Run the test:
./gradlew test --tests '*EmailValidatorTest'Check that it fails because validateEmail is missing or not done. Then add the least code needed:
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 @")
)
}
return Result.success(email)
}Run the test again. Then run all tests:
./gradlew testAdd more rules only when the app needs them. Do not claim full email rule support from a small check.
Edge Cases
Check cases that fit the code:
- Empty and blank text
- Null values when the type allows null
- Zero and negative numbers
- Min and max values
- Empty and very large lists
- Duplicate items
- Unicode text
- Time zones and daylight saving time
- Missing files
- Bad data
- Timeouts
- Cancelled coroutines
- Failed work after part of a task is done
- Calls made more than once
- Shared state between tests
Use fixed clocks, test data, and random seeds. Tests must not depend on the current time, test order, local machine, or internet.
Kover Coverage
Use the Kover tasks already set by the project. Common tasks are:
./gradlew koverHtmlReport
./gradlew koverVerifyOpen the HTML report and check missed branches, not only the total score.
Aim for 80 percent or the project rule, whichever is set. Coverage is a guide. A high score does not prove good tests. Do not add weak tests only to raise the number. Do not test generated code unless the project asks for it.
Final Check
Before finishing:
- Run the changed test by itself.
- Run the full test set.
- Check that no test depends on run order.
- Check that coroutine jobs end.
- Check that mocks do not leak between tests.
- Check key errors and edge cases.
- Run Kover if coverage is part of the task.
- Report any test you could not run and why.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

