unit-tests
它能做什么
这个技能为代码库添加有针对性的单元测试,从最重要的逻辑开始。它面向希望修改代码时更有信心的开发者。
适用场景
- ✓项目中重要的函数或组件没有单元测试的时候。
- ✓有人希望在重构风险较高的代码之前先建立测试的时候。
- ✓团队要求在 CI 中运行测试,以便及早发现回归问题的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/unit-tests/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们的结账计算没有测试,我不敢改它。请帮我为关键逻辑编写单元测试吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出没有测试的函数,并编写有针对性的测试,描述预期行为。它会模拟外部服务而不是内部模块,使测试保持可靠。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Write unit tests
Unit tests catch bugs before they reach production, serve as documentation for expected behavior, and give developers confidence to refactor code without breaking functionality.
Quick Reference
- Test business logic, utilities, and edge cases
- Aim for 80%+ coverage on critical paths
- Use descriptive test names that explain behavior
- Mock external dependencies, not internal modules
- Run tests in CI to catch regressions early
Check
Check if this codebase has unit tests with good coverage for critical functionality.
Fix
Write unit tests for untested functions and components to improve code reliability.
Explain
Explain how unit tests catch bugs early and serve as documentation for expected behavior.
Code Review
Review tests, CI workflows, and enforcement points related to Write unit tests. Flag exact gaps where the rule is not automatically verified or where failures do not block regressions.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/testing/unit-tests
常见问题
测试覆盖率多少才够?
这个技能目标是关键路径达到 80% 或更高,而不是把每一行都视为同等重要。
测试应该自动运行吗?
应该。这个技能建议在 CI 中运行它们,以便及早发现回归问题。
什么样的测试名称才好?
描述性的名称,说明所检查的行为。
详情
作者的原始描述
Use when reviewing CI coverage, automated checks, or test strategy related to Write unit tests. Focus on whether the rule is continuously verified, not just documented.
热度
- GitHub 星标
- 75k
- 排名
- #3070
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。