‹ 首页

approval-tests

@lexler · 收录于 昨天 · 上游提交 1 周前

Writes approval tests (snapshot/golden master testing) for Python, JavaScript/TypeScript, or Java. Use when verifying complex output, characterization testing legacy code, testing combinations, or working with .approved/.received files.

适合你,如果经常需要为遗留代码或复杂输出创建快照测试。

/ 通过 npx 安装 校验哈希
npx oh-my-skill add lexler/skill-factory/approval-tests
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- lexler/skill-factory/approval-tests
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify lexler/skill-factory/approval-tests
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
223GitHub stars
~983最小装载
~2.8K含声明引用
~16.3K文本包总量
索引托管

怎么用

商店整理自技能原文 · 版本 2eae60e · 表述以原文为准
它做什么

装上后,Claude能编写审批测试(快照测试),用于Python、JavaScript/TypeScript或Java。它会生成测试代码,通过比较输出与已批准的“黄金主”文件来验证,无需编写单个断言。

什么时候触发

当用户要求验证复杂输出、描述遗留代码或测试组合时触发。

装好后可以这样说
Claude会生成使用verify()的测试代码。
Claude会生成审批测试来捕获当前行为。
Claude会生成组合测试代码。
技能原文 SKILL.md作者撰写 · Apache-2.0 · 2eae60e

STARTER_CHARACTER = 📸

Approval Tests

Philosophy

"A picture's worth 1000 assertions."

Approval tests verify complex output by comparing against a saved "golden master" file instead of writing individual assertions. You capture the output once, review it, approve it, and future runs compare against that approved snapshot.

You don't need to know the expected output upfront. Run the code, see what it produces, decide if it's correct. Approval is a judgment - you're confirming this is what the code should produce. Whoever writes the code reviews and approves.

Use approval tests when:

  • Output is complex - instead of 20 assertions, one approval captures everything
  • Characterizing legacy code - snapshot behavior, then refactor safely
  • Combinatorial testing - test all input combinations in one approval
  • Assertions would be tedious or brittle

Use assertions when:

  • Simple values or specific edge cases
  • Non-deterministic output that can't be scrubbed
Core Workflow
1. Write test with verify(result)
2. Run test → FAILS (no .approved file yet)
3. Creates: TestName.approved.txt (empty) + TestName.received.txt (actual output)
4. Review .received file - is this correct?
5. YES → rename/copy .received to .approved
6. Run test again → PASSES
7. Commit .approved file to version control

File naming convention:

{TestClass}.{test_method}.approved.txt   ← commit this
{TestClass}.{test_method}.received.txt   ← gitignore this

Critical rules:

  • .approved files ARE your test expectations - commit them
  • .received files are temporary - add *.received.* to .gitignore
  • Never edit .approved files by hand - always generate via test

When a test fails, a diff tool opens showing approved vs received. This is how you review changes. Reporters configure which diff tool to use.

Core API Pattern

All languages follow the same pattern:

verify(result)                    # Basic string/object verification
verify_as_json(object)            # Objects as formatted JSON
verify_all(header, items)         # Collections with labels
verify_all_combinations(fn, inputs)  # All input combinations

Non-deterministic data (timestamps, GUIDs) must be scrubbed before verification.

Key Techniques
  • Scrubbers - replace values that change between runs (timestamps, UUIDs, random numbers, ports, paths) with stable placeholders like [Date1] or guid_1. Without scrubbing, tests pass locally but fail in CI.
  • Inline approvals - expectations in source code instead of separate files. Avoids file proliferation for short output. Python uses docstrings, Java uses text blocks.
  • Storyboard - show an object at multiple points in time, like frames in a comic. Each step appears in the diff, making it easy to see how state changes. For workflows, state machines, animations. Python/Java have classes; Node.js uses string building.
  • Combinations - test all permutations of input parameters in one approval. Exhaustive coverage without writing separate tests for each case. For large sets, pairwise testing reduces millions of combinations to ~100.
  • Multiple approvals per test - calling verify() twice overwrites the same file, so only the last one is tested. Parameter-based naming creates separate files for each scenario.

See language references for implementation details.

Language References

Detect language from project files, then read the appropriate reference for installation, quick start, core patterns, and links to deeper reference files:

  • [python.md](python.md) - Python (pyproject.toml, setup.py, requirements.txt)
  • [nodejs.md](nodejs.md) - JavaScript/TypeScript (package.json)
  • [java.md](java.md) - Java (pom.xml, build.gradle)
Anti-Patterns
  • Don't write assertions for complex objects - use verify_as_json() instead
  • Don't commit .received files - they're temporary
  • Don't forget scrubbers for timestamps, GUIDs, random values
  • Don't over-verify - one approval per logical behavior. Large approvals hide signal in noise; unrelated changes break tests.
  • Don't hand-edit .approved files - always generate via test. Hand-edited files may not match actual code output.
  • Don't use verify_all for structured data - use verify_as_json({"items": items})
  • Don't mix approvals with assertions - the approval captures everything
  • Don't call verify() multiple times without NamerFactory - each overwrites the same file

Flaky tests across environments usually means unscrubbed dynamic data (timestamps, UUIDs, ports, paths).

按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。