为指定函数、模块或文件编写单元测试,覆盖正常、边界和异常情况。当用户说"写测试/加单测/test 一下"时使用。
Scanned 9/6/2026
Install to Claude Code
npx -y skills add Ducktang123/claude-code-deepseek --skill write-tests --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Write Tests?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/ducktang123-write-tests)More formats (shields.io, HTML) on the badges page.
---
name: write-tests
description: 为指定函数、模块或文件编写单元测试,覆盖正常、边界和异常情况。当用户说"写测试/加单测/test 一下"时使用。
---
# 编写单元测试
为目标代码写实用、可运行的测试。
## 步骤
1. **识别测试框架**:先看项目里已有的测试用什么框架/写法(如 pytest、jest、JUnit、go test 等),保持一致;没有就按语言主流框架。
2. **分析被测对象**:理清输入、输出、副作用、依赖。
3. **设计用例**,至少覆盖:
- 正常路径(典型输入)。
- 边界值(空、0、最大/最小、单元素等)。
- 异常/错误输入(非法参数、抛异常)。
4. **编写测试**:命名清晰(说明在测什么),断言明确,必要时 mock 外部依赖。
5. **运行验证**:实际跑一遍测试,确保通过;失败则修正测试或指出是被测代码的问题。
## 原则
- 测试要能真正运行,不要写完不验证。
- 一个测试只测一件事。
- 不为了覆盖率而写无意义的断言。
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!