跳到主要内容

testing 精选

Testing workflow and quality standards for writing and running tests. Use when: (1) Writing new tests, (2) Adding a new feature that needs tests, (3) Modifying logic that has existing tests, (4) Before claiming a task is complete.

在 GitHub 打开

安装方式

cp -r .claude/skills/testing ~/.claude/skills/testing

把该 skill 目录放进客户端 skills 目录。不同客户端的目录可能不同,Claude Code 默认是 ~/.claude/skills/

整仓一次性获取:git clone --depth 1 https://github.com/iOfficeAI/AionUi.git

依赖与权限

  • 无需 API Key
  • 无需联网
  • 依赖外部命令:node bun playwright
  • 以上为按正文与 frontmatter 自动推断的信号,仅供参考;安装前建议先阅读原文。
触发场景
(1) Writing new tests(3) Modifying logic that

SKILL.md 正文

来源 iOfficeAI/AionUi@6744099 · 许可 Apache-2.0 · 内容未修改

Testing Skill

Standards and workflow for writing and running tests. Every feature must be tested.

Announce at start: "I'm using testing skill to ensure proper test coverage."

Trigger Conditions

  • Writing new tests for a feature or bug fix
  • Adding a new feature (must include tests)
  • Modifying logic that has existing tests (must update them)
  • Before claiming work is complete
  • Before committing code

Framework

Vitest 4 — configured in vitest.config.ts.

Test Structure

tests/
├── unit/          # Individual functions, utilities, components
├── integration/   # IPC, database, service interactions
├── regression/    # Regression test cases
└── e2e/           # End-to-end tests (Playwright, playwright.config.ts)

Two Test Environments

EnvironmentWhenFile naming
node (default)Main process, utilities, services*.test.ts
jsdomDOM/browser-dependent code*.dom.test.ts

Workflow

Step 1: Identify What to Test

Before writing tests, list the riskiest scenarios first:

  • What happens when the dependency returns undefined / throws?
  • What happens at boundaries (empty list, max retries, past timestamp)?
  • What is most likely to break in production?

Step 2: Write Tests

Follow these quality rules:

1. Describe behavior, not code structure

// Wrong — describes implementation
it('should call repo.getConversation', ...)

// Correct — describes behavior
it('should return cached task without hitting repo on second call', ...)
it('should reject with error when conversation does not exist', ...)

2. Every describe block must cover at least one failure path

Happy-path-only tests leave the most dangerous code untested.

3. One behavior per test

Keep each it() focused. More than 3 expect() calls in one test is a signal it is testing too much at once.

4. Self-check

After writing a test, mentally delete the core logic it targets. If the test would still pass, rewrite it — it is not guarding anything.

5. Start from risk, not from coverage gaps

List scenarios most likely to produce bugs. Write those first. Coverage is the outcome, not the starting point.

Step 3: Run Tests

bun run test              # Run all tests (REQUIRED before every commit)
bun run test:coverage     # Check coverage (before opening a PR)

Step 4: Verify Coverage

Coverage target: ≥ 80% for all source files matched by vitest.config.ts → coverage.include (currently src/**/*.{ts,tsx} plus a few scripts).

New source files are automatically included in coverage — no manual config changes needed. If a new file is accidentally excluded by a rule in coverage.exclude, remove it from the exclude list.

Step 5: Update Existing Tests

When modifying logic, check if existing tests need updating:

bun run test -- --reporter=verbose   # See which tests pass/fail with names

If a test fails because the behavior changed intentionally, update the test. If it fails unexpectedly, investigate.

Edge Case Checklist

When testing a module, verify:

  • [ ] null / undefined inputs handled
  • [ ] Empty arrays/objects handled
  • [ ] Error thrown by dependencies handled
  • [ ] Boundary values (0, -1, max, empty string)
  • [ ] Async operations (timeout, rejection, cancellation)

Quick Checklist

Before submitting code:

  • [ ] New features have corresponding test cases
  • [ ] Modified logic has updated tests
  • [ ] bun run test passes
  • [ ] Tests describe behavior, not implementation
  • [ ] At least one failure path per describe block
  • [ ] New source files are not accidentally excluded by coverage.exclude
  • [ ] bun run test:coverage meets ≥ 80% target

Common Mistakes

MistakeCorrect
Testing implementation detailsTest observable behavior
Only testing happy pathMust include at least one failure path
5+ expects in one it()Split into separate tests
Skipping tests for "simple" codeSimple code breaks too — test the risky parts
Writing tests after saying "done"Tests are part of "done", not an afterthought

质量与来源

所属仓库
iOfficeAI/AionUi
仓库星标
3.3 万
最近更新
1 个月前
采集时间
今天
commit
6744099b279b
内容指纹
sha256:a40418b4bc172b5
文件路径
.claude/skills/testing/SKILL.md

相似 Skill

更多「编码」
access
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the Discord channel.
精选 anthropics/claude-plugins-official 3.8 万 原文
Claude CodeMCP 客户端
configure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how do I set this up" or "who can reach me," or wants to check channel status.
精选 anthropics/claude-plugins-official 3.8 万 原文
Claude CodeMCP 客户端
access
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the iMessage channel.
精选 anthropics/claude-plugins-official 3.8 万 原文
Claude CodeMCP 客户端
configure
Check iMessage channel setup and review access policy. Use when the user asks to configure iMessage, asks "how do I set this up" or "who can reach me," or wants to know why texts aren't reaching the assistant.
精选 anthropics/claude-plugins-official 3.8 万 原文
Claude CodeMCP 客户端
access
Manage Telegram channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the Telegram channel.
精选 anthropics/claude-plugins-official 3.8 万 原文
Claude CodeMCP 客户端
configure
Set up the Telegram channel — save the bot token and review access policy. Use when the user pastes a Telegram bot token, asks to configure Telegram, asks "how do I set this up" or "who can reach me," or wants to check channel status.
精选 anthropics/claude-plugins-official 3.8 万 原文
Claude CodeMCP 客户端