test-helpers
它能做什么
这个技能为游戏项目创建可复用的测试辅助代码,并与其引擎和系统相匹配。适合编写大量测试、希望减少重复初始化代码的开发者。
适用场景
- ✓当团队完成测试设置,希望有共享的辅助函数来编写测试的时候。
- ✓当开发者在多个测试中不断重复相同的初始化和断言的时候。
- ✓当新的引擎测试文件夹需要起步用的辅助函数的时候。
技能链接
https://github.com/Donchitos/Claude-Code-Game-Studios/blob/main/.claude/skills/test-helpers/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的 Godot 项目创建测试辅助代码,让我们的测试需要的重复初始化代码更少。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能会检查项目的引擎和语言,然后在引擎测试运行器使用的文件夹中,编写用于初始化、断言、工厂和模拟的辅助文件。某些改动它会先询问你。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
!bash "${CLAUDE_SKILL_DIR}/../../hooks/yaml-helper.sh" resolve_config --keys automation
Automation mode: Resolve modes.automation (project.local.yaml →
project.yaml → default collaborative). Every AskUserQuestion call and
every file write follows .claude/docs/automation-modes.md
(collaborative asks always · guided major-only · autonomous logs and proceeds;
automation_always_ask categories always prompt).
Test Helpers
Writing test cases is faster and more consistent when common setup, teardown,
and assertion patterns are abstracted into helpers. This skill generates a
tests/helpers/ library tailored to the project's actual engine, language,
and systems — so every developer writes less boilerplate and more assertions.
Output: engine-specific helper files in the engine's helper root —
the only place its test runner compiles them (.claude/docs/directory-structure.md):
| Engine | Helper root |
|---|---|
| Godot | tests/helpers/ |
| Unity | Assets/Tests/EditMode/Helpers/ — inside the EditModeTests assembly /test-setup creates. If PlayMode tests need the same helpers, ask before creating Assets/Tests/Helpers/TestHelpers.asmdef and referencing it from both test assemblies. |
| Unreal | Source/<Module>/Private/Tests/Helpers/ |
tests/helpers/ below means the helper root for the project's engine.
When to run:
- After
/test-setupscaffolds the framework (first time) - When multiple test files repeat the same setup boilerplate
- When starting to write tests for a new system
Assertions: use the project's test framework, never bare assert()
Generated helpers must assert through the configured test framework's assertion
API, resolved from testing.framework — not through GDScript's built-in
assert().
Two things go wrong with a bare assert() in a helper, and both are silent:
- It aborts the run instead of failing the test. A framework assertion
records a failure and continues, so one broken expectation yields one red test.
A bare
assert()halts execution, so the first failure hides every result after it. - It is stripped in release builds. A helper library built on
assert()stops asserting entirely in exactly the build you most want checked, and does so without any error — the tests still "pass".
Look up the assertion form for the configured framework before generating
code. Do not copy the forms in this file or in other skills' examples as
authoritative — they are illustrative and have drifted (assert_eq,
assert_true and assert_that all appear across the repo). If you cannot
confirm the correct API for the project's framework, say so and generate no
helper rather than guessing.
Helpers must not extend the framework's test-suite base class. A file in
tests/helpers/ that extends the suite type is discovered by the runner as a
test suite containing zero tests. Helpers are plain classes; only real test files
extend the suite.
1. Parse Arguments
Modes:
/test-helpers [system-name]— generate helpers for a specific system (e.g.,/test-helpers combat)/test-helpers all— generate helpers for all systems with test files/test-helpers scaffold— generate only the base helper library (no system-specific helpers); use this on first run- No argument — run
scaffoldif no helpers exist, elseall
2. Detect Engine and Language
Read from project.yaml first, falling back to .claude/docs/technical-preferences.md for any key that is absent or empty:
engine.name(else theEngine:value)engine.language(else theLanguage:value)testing.framework(elseFramework:from the Testing section)
If the engine is not configured in either source: "Engine not configured. Run /setup-engine first."
3. Load Existing Test Patterns
Scan the engine's test root for patterns already in use (Godot tests/, Unity
Assets/Tests/, Unreal Source/<Module>/Private/Tests/):
Glob pattern="tests/**/*_test.*" (Godot)
Glob pattern="Assets/Tests/**/*Tests.cs" (Unity)
Glob pattern="Source/*/Private/Tests/**/*.cpp" (Unreal)
For a representative sample (up to 5 files), read the test files and extract:
- Setup patterns (how
before_each/setUp/ fixtures are written) - Common assertion patterns (what is being asserted most often)
- Object creation patterns (how game objects or scenes are instantiated in tests)
- Mock/stub patterns (h
常见问题
它适用于任何引擎吗?
它会针对项目的引擎进行定制,例如 Godot、Unity 或 Unreal,每个引擎都有自己的辅助文件夹。
我应该先运行测试设置吗?
应该。这些辅助代码基于测试框架构建,所以最好先完成测试设置。
它会替我编写测试吗?
它只编写辅助代码以减少样板代码,测试本身仍由开发者编写。
详情
作者的原始描述
Generate engine-specific test helper libraries — assertion utilities, factory functions, mocks in the engine's test folder. Reduces boilerplate.
热度
- GitHub 星标
- 33k
- 排名
- #8503
- 许可证
- MIT
- 更新时间
- 2026/10/18
评论
- …