kotlin-testing

使用Kotest、MockK、协程测试、基于属性的测试和Kover覆盖率的Kotlin测试模式。遵循TDD方法论和地道的Kotlin实践。

Content Preview
---
name: kotlin-testing
description: 使用Kotest、MockK、协程测试、基于属性的测试和Kover覆盖率的Kotlin测试模式。遵循TDD方法论和地道的Kotlin实践。
origin: ECC
---

# Kotlin 测试模式

遵循 TDD 方法论,使用 Kotest 和 MockK 编写可靠、可维护测试的全面 Kotlin 测试模式。

## 何时使用

* 编写新的 Kotlin 函数或类
* 为现有 Kotlin 代码添加测试覆盖率
* 实现基于属性的测试
* 在 Kotlin 项目中遵循 TDD 工作流
* 为代码覆盖率配置 Kover

## 工作原理

1. **确定目标代码** — 找到要测试的函数、类或模块
2. **编写 Kotest 规范** — 选择与测试范围匹配的规范样式(StringSpec、FunSpec、BehaviorSpec)
3. **模拟依赖项** — 使用 MockK 来隔离被测单元
4. **运行测试(红色阶段)** — 验证测试是否按预期失败
5. **实现代码(绿色阶段)** — 编写最少
How to Use

Recommended: Install to project (local)

mkdir -p .claude/skills
curl -o .claude/skills/kotlin-testing.md \
  https://raw.githubusercontent.com/affaan-m/everything-claude-code/main/docs/zh-CN/skills/kotlin-testing/SKILL.md

Skill is scoped to this project only. Add .claude/skills/ to your .gitignoreif you don't want to commit it.

Alternative: Clone full repo

git clone https://github.com/affaan-m/everything-claude-code

Then reference at docs/zh-CN/skills/kotlin-testing/SKILL.md

Related Skills