{"data":{"slug":"github-donchitos-claude-code-game-studios-claude-skills-test-helpers-889b148cd3be","title":"Generate Engine-Specific Test Helpers for Assertion Utilities, Factory Functions, and Mocks","summary":"Create engine-specific test helpers for assertion utilities, factory functions, and mocks in the engine's test folder. Helpers are generated based on the project's test framework and must not use bare `assert()`; they are a starting point for test development and must align with the project's GDD.","url":"https:\/\/skillshunter.net\/skills\/github-donchitos-claude-code-game-studios-claude-skills-test-helpers-889b148cd3be","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-donchitos-claude-code-game-studios-claude-skills-test-helpers-889b148cd3be","markdown_url":"https:\/\/skillshunter.net\/skills\/github-donchitos-claude-code-game-studios-claude-skills-test-helpers-889b148cd3be.md","download_url":"https:\/\/skillshunter.net\/skills\/github-donchitos-claude-code-game-studios-claude-skills-test-helpers-889b148cd3be\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before generating code, confirm the correct assertion API for the project's test framework. If it cannot be confirmed, no helper should be generated. Generated code must use the framework's assertion API, not GDScript's built-in `assert()`. Always check for existing helpers to avoid overwriting them.","instructions":"---\nname: test-helpers\ndescription: \"Generate engine-specific test helper libraries \u2014 assertion utilities, factory functions, mocks in the engine's test folder. Reduces boilerplate.\"\nargument-hint: \"[system-name | all | scaffold]\"\nuser-invocable: true\nallowed-tools: Read, Glob, Grep, Write, Bash(bash \"*\/.claude\/skills\/test-helpers\/..\/..\/hooks\/yaml-helper.sh\" resolve_config *)\nmodel: sonnet\n---\n\n!`bash \"${CLAUDE_SKILL_DIR}\/..\/..\/hooks\/yaml-helper.sh\" resolve_config --keys automation`\n\n**Automation mode**: Resolve `modes.automation` (`project.local.yaml` \u2192\n`project.yaml` \u2192 default `collaborative`). Every `AskUserQuestion` call and\nevery file write follows `.claude\/docs\/automation-modes.md`\n(collaborative asks always \u00b7 guided major-only \u00b7 autonomous logs and proceeds;\n`automation_always_ask` categories always prompt).\n\n# Test Helpers\n\nWriting test cases is faster and more consistent when common setup, teardown,\nand assertion patterns are abstracted into helpers. This skill generates a\n`tests\/helpers\/` library tailored to the project's actual engine, language,\nand systems \u2014 so every developer writes less boilerplate and more assertions.\n\n**Output:** engine-specific helper files in the engine's **helper root** \u2014\nthe only place its test runner compiles them (`.claude\/docs\/directory-structure.md`):\n\n| Engine | Helper root |\n|---|---|\n| Godot | `tests\/helpers\/` |\n| Unity | `Assets\/Tests\/EditMode\/Helpers\/` \u2014 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. |\n| Unreal | `Source\/<Module>\/Private\/Tests\/Helpers\/` |\n\n`tests\/helpers\/` below means the helper root for the project's engine.\n\n**When to run:**\n- After `\/test-setup` scaffolds the framework (first time)\n- When multiple test files repeat the same setup boilerplate\n- When starting to write tests for a new system\n\n---\n\n## Assertions: use the project's test framework, never bare `assert()`\n\n**Generated helpers must assert through the configured test framework's assertion\nAPI**, resolved from `testing.framework` \u2014 not through GDScript's built-in\n`assert()`.\n\nTwo things go wrong with a bare `assert()` in a helper, and both are silent:\n\n1. **It aborts the run instead of failing the test.** A framework assertion\n   records a failure and continues, so one broken expectation yields one red test.\n   A bare `assert()` halts execution, so the first failure hides every result\n   after it.\n2. **It is stripped in release builds.** A helper library built on `assert()`\n   stops asserting entirely in exactly the build you most want checked, and does\n   so without any error \u2014 the tests still \"pass\".\n\n**Look up the assertion form for the configured framework before generating\ncode.** Do not copy the forms in this file or in other skills' examples as\nauthoritative \u2014 they are illustrative and have drifted (`assert_eq`,\n`assert_true` and `assert_that` all appear across the repo). If you cannot\nconfirm the correct API for the project's framework, say so and generate no\nhelper rather than guessing.\n\n**Helpers must not extend the framework's test-suite base class.** A file in\n`tests\/helpers\/` that extends the suite type is discovered by the runner as a\ntest suite containing zero tests. Helpers are plain classes; only real test files\nextend the suite.\n\n---\n\n## 1. Parse Arguments\n\n**Modes:**\n- `\/test-helpers [system-name]` \u2014 generate helpers for a specific system\n  (e.g., `\/test-helpers combat`)\n- `\/test-helpers all` \u2014 generate helpers for all systems with test files\n- `\/test-helpers scaffold` \u2014 generate only the base helper library (no\n  system-specific helpers); use this on first run\n- No argument \u2014 run `scaffold` if no helpers exist, else `all`\n\n---\n\n## 2. Detect Engine and Language\n\nRead from `project.yaml` first, falling back to `.claude\/docs\/technical-preferences.md` for any key that is absent or empty:\n- `engine.name` (else the `Engine:` value)\n- `engine.language` (else the `Language:` value)\n- `testing.framework` (else `Framework:` from the Testing section)\n\nIf the engine is not configured in either source: \"Engine not configured. Run `\/setup-engine` first.\"\n\n---\n\n## 3. Load Existing Test Patterns\n\nScan the engine's test root for patterns already in use (Godot `tests\/`, Unity\n`Assets\/Tests\/`, Unreal `Source\/<Module>\/Private\/Tests\/`):\n\n```\nGlob pattern=\"tests\/**\/*_test.*\"                  (Godot)\nGlob pattern=\"Assets\/Tests\/**\/*Tests.cs\"          (Unity)\nGlob pattern=\"Source\/*\/Private\/Tests\/**\/*.cpp\"    (Unreal)\n```\n\nFor a representative sample (up to 5 files), read the test files and extract:\n- Setup patterns (how `before_each` \/ `setUp` \/ fixtures are written)\n- Common assertion patterns (what is being asserted most often)\n- Object creation patterns (how game objects or scenes are instantiated in tests)\n- Mock\/stub patterns (how dependencies are replaced)\n\nThis ensures generated helpers match the project's existing style, not a\ngeneric template.\n\nAlso read:\n- `design\/gdd\/systems-index.md` \u2014 to know which systems exist\n- In-scope GDD(s) \u2014 to understand what data types and values need testing. Read\n  them by section: find the headings you need with the Grep tool (pattern `^#`,\n  content mode) and Read those ranges with offset and limit.\n- `docs\/architecture\/tr-registry.yaml` \u2014 to map requirements to tested systems\n\n---\n\n## 4. Generate Engine-Specific Helpers\n\n### Godot 4 (GDUnit4 \/ GDScript)\n\n> **`FAIL_IF(...)` in the example below is a PLACEHOLDER, not an API.** It marks\n> the one line you must resolve from the project's actual test framework before\n> emitting any of this, per the rule in \u00a72. Substitute the framework's real\n> failure call \u2014 the form that **registers a failure with the runner and lets the\n> suite continue** \u2014 and delete the marker comment.\n>\n> **It is deliberately not spelled `assert_that`, `assert_eq` or `assert_true`.**\n> All three appear somewhere in this repo, they disagree, and **GdUnit4's API is\n> not covered by `docs\/engine-reference\/`** \u2014 so writing any of them here would be\n> asserting an API this repo cannot source, in the file whose whole job is to stop\n> people doing that. If you cannot confirm the correct call for the configured\n> framework, \u00a72 already tells you the answer: **generate no helper.** An\n> unresolved `FAIL_IF` reaching disk is a bug; a missing helper is a task.\n>\n> Worked examples must obey \u00a72 too \u2014 a bare `assert()` here would be the exact\n> form \u00a72 forbids, sixty lines below \u00a72 forbidding it. A rule stated in prose\n> does not reach its own worked example unless someone makes it.\n\n**Base helper** (`tests\/helpers\/game_assertions.gd`):\n\n```gdscript\n## Game-specific assertion utilities for [Project Name] tests.\n## Domain-specific helpers built on the project's test framework.\n##\n## Usage (static \u2014 no instance needed):\n##   GameAssertions.assert_in_range(entity.health, 0, entity.max_health, \"health\")\n\nclass_name GameAssertions\nextends RefCounted\n\n## Assert a value is within the inclusive range [min_val, max_val].\n## Use for any formula output that has defined bounds in a GDD.\nstatic func assert_in_range(\n    value: float,\n    min_val: float,\n    max_val: float,\n    label: String = \"value\"\n) -> void:\n    # FRAMEWORK ASSERT \u2014 resolve per the rule above; do not emit `assert()`.\n    FAIL_IF(\n        not (value >= min_val and value <= max_val),\n        \"%s %.2f is outside expected range [%.2f, %.2f]\" % [label, value, min_val, max_val]\n    )\n\n## Assert a signal was emitted during a callable block.\n## Usage: assert_signal_emitted(entity, \"health_changed\", func(): entity.take_damage(10))\nstatic func assert_signal_emitted(\n    obj: Object,\n    signal_name: String,\n    action: Callable\n) -> void:\n    # A lambda captures a local by value: `emitted = true` inside it would set\n    # the lambda's own copy. Mutate a Dictionary it shares instead. `...args`\n    # (4.5+) accepts a signal with any number of arguments.\n    var state := {\"emitted\": false}\n    obj.connect(signal_name, func(...args): state.emitted = true)\n    action.call()\n    # FRAMEWORK ASSERT \u2014 resolve per the rule above; do not emit `assert()`.\n    FAIL_IF(not state.emitted, \"Expected signal '%s' to be emitted, but it was not.\" % signal_name)\n\n## Assert that a callable does NOT emit a signal.\nstatic func assert_signal_not_emitted(\n    obj: Object,\n    signal_name: String,\n    action: Callable\n) -> void:\n    var state := {\"emitted\": false}  # a Dictionary, as above\n    obj.connect(signal_name, func(...args): state.emitted = true)\n    action.call()\n    # FRAMEWORK ASSERT \u2014 resolve per the rule above; do not emit `assert()`.\n    FAIL_IF(state.emitted, \"Expected signal '%s' NOT to be emitted, but it was.\" % signal_name)\n\n## Assert a node exists at path within a parent.\nstatic func assert_node_exists(parent: Node, path: NodePath) -> void:\n    # FRAMEWORK ASSERT \u2014 resolve per the rule above; do not emit `assert()`.\n    FAIL_IF(\n        not parent.has_node(path),\n        \"Expected node at path '%s' to exist.\" % str(path)\n    )\n```\n\n**Factory helper** (`tests\/helpers\/game_factory.gd`):\n\n```gdscript\n## Factory functions for creating test game objects.\n## Returns minimal objects configured for unit testing (no scene tree required).\n##\n## Usage: var player = GameFactory.make_player(health: 100)\n\nclass_name GameFactory\nextends RefCounted\n\n## Create a minimal player-like object for testing.\n## Override fields as needed.\nstatic func make_player(health: int = 100) -> Node:\n    var player = Node.new()\n    player.set_meta(\"health\", health)\n    player.set_meta(\"max_health\", health)\n    return player\n```\n\n**Scene helper** (`tests\/helpers\/scene_runner_helper.gd`):\n\n```gdscript\n## Utilities for scene-based integration tests. For input simulation and frame\n## stepping, use gdUnit4's own `scene_runner()` from inside the suite.\n\nclass_name SceneRunnerHelper\nextends RefCounted\n\n## Load a scene under `host` \u2014 the calling test suite, which passes `self` \u2014\n## and wait one frame for _ready() to complete. A plain class, so the runner\n## never discovers this file as a suite with zero tests.\nstatic func load_scene_and_wait(host: Node, scene_path: String) -> Node:\n    var scene: Node = load(scene_path).instantiate()\n    host.add_child(scene)\n    await host.get_tree().process_frame\n    return scene\n```\n\n---\n\n### Unity (NUnit \/ C#)\n\n**Base helper** (`Assets\/Tests\/EditMode\/Helpers\/GameAssertions.cs`):\n\n```csharp\nusing NUnit.Framework;\nusing UnityEngine;\n\n\/\/\/ <summary>\n\/\/\/ Game-specific assertion utilities for [Project Name] tests.\n\/\/\/ Extends NUnit's Assert with domain-specific helpers.\n\/\/\/ <\/summary>\npublic static class GameAssertions\n{\n    \/\/\/ <summary>\n    \/\/\/ Assert a value is within an inclusive range [min, max].\n    \/\/\/ Use for any formula output defined in GDD Formulas sections.\n    \/\/\/ <\/summary>\n    public static void AssertInRange(float value, float min, float max, string label = \"value\")\n    {\n        Assert.That(value, Is.InRange(min, max),\n            $\"{label} ({value:F2}) is outside expected range [{min:F2}, {max:F2}]\");\n    }\n\n    \/\/\/ <summary>Assert a UnityEvent or C# event was raised during an action.<\/summary>\n    public static void AssertEventRaised(ref bool wasCalled, System.Action action, string eventName)\n    {\n        wasCalled = false;\n        action();\n        Assert.IsTrue(wasCalled, $\"Expected event '{eventName}' to be raised, but it was not.\");\n    }\n\n    \/\/\/ <summary>Assert a component exists on a GameObject.<\/summary>\n    public static void AssertHasComponent<T>(GameObject obj) where T : Component\n    {\n        var component = obj.GetComponent<T>();\n        Assert.IsNotNull(component,\n            $\"Expected GameObject '{obj.name}' to have component {typeof(T).Name}.\");\n    }\n}\n```\n\n**Factory helper** (`Assets\/Tests\/EditMode\/Helpers\/GameFactory.cs`):\n\n```csharp\nusing UnityEngine;\n\n\/\/\/ <summary>\n\/\/\/ Factory methods for creating minimal test objects without loading scenes.\n\/\/\/ <\/summary>\npublic static class GameFactory\n{\n    \/\/\/ <summary>Create a minimal GameObject with a named component for testing.<\/summary>\n    public static GameObject MakeGameObject(string name = \"TestObject\")\n    {\n        var go = new GameObject(name);\n        return go;\n    }\n\n    \/\/\/ <summary>\n    \/\/\/ Create a ScriptableObject of type T for data-driven tests.\n    \/\/\/ Dispose with Object.DestroyImmediate after test.\n    \/\/\/ <\/summary>\n    public static T MakeScriptableObject<T>() where T : ScriptableObject\n    {\n        return ScriptableObject.CreateInstance<T>();\n    }\n}\n```\n\n---\n\n### Unreal Engine (C++)\n\n**Base helper** (`Source\/<Module>\/Private\/Tests\/Helpers\/GameTestHelpers.h`):\n\n```cpp\n#pragma once\n\n#include \"CoreMinimal.h\"\n#include \"Misc\/AutomationTest.h\"\n\n\/**\n * Game-specific assertion macros and helpers for [Project Name] automation tests.\n * Include in any test file that needs domain-specific assertions.\n *\n * Usage:\n *   GAME_TEST_ASSERT_IN_RANGE(TestName, DamageValue, 10.0f, 50.0f, TEXT(\"Damage\"));\n *\/\n\n\/\/ Assert a float value is within inclusive range [Min, Max]\n#define GAME_TEST_ASSERT_IN_RANGE(TestName, Value, Min, Max, Label) \\\n    TestTrue( \\\n        FString::Printf(TEXT(\"%s (%.2f) in range [%.2f, %.2f]\"), Label, Value, Min, Max), \\\n        (Value) >= (Min) && (Value) <= (Max) \\\n    )\n\n\/\/ Assert a UObject pointer is valid (not null, not garbage collected)\n#define GAME_TEST_ASSERT_VALID(TestName, Ptr, Label) \\\n    TestTrue( \\\n        FString::Printf(TEXT(\"%s is valid\"), Label), \\\n        IsValid(Ptr) \\\n    )\n\n\/\/ Assert an Actor is in the world (spawned successfully)\n#define GAME_TEST_ASSERT_SPAWNED(TestName, ActorPtr, ClassName) \\\n    TestNotNull( \\\n        FString::Printf(TEXT(\"Spawned actor of class %s\"), TEXT(#ClassName)), \\\n        ActorPtr \\\n    )\n\n\/**\n * Helper to create a minimal test world.\n * Remember to call World->DestroyWorld(false) in teardown.\n *\/\nnamespace GameTestHelpers\n{\n    inline UWorld* CreateTestWorld(const FString& WorldName = TEXT(\"TestWorld\"))\n    {\n        UWorld* World = UWorld::CreateWorld(EWorldType::Game, false);\n        FWorldContext& WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game);\n        WorldContext.SetCurrentWorld(World);\n        return World;\n    }\n}\n```\n\n---\n\n## 5. Generate System-Specific Helpers\n\nFor `[system-name]` or `all` modes, generate a helper per system:\n\nRead only the GDD sections this needs \u2014 `Grep pattern=\"^## ([0-9]+\\. )?(Formulas|Edge Cases|Detailed Rules|Detailed Design)\" path=\"design\/gdd\/[system].md\" output_mode=\"content\" -A 30` (the optional number matches a reverse-documented GDD's `## 4. Formulas`) \u2014 rather than a full read (every peer skill section-greps GDDs; in `all` mode a full read multiplies across each system's 400+-line GDD). Extract:\n- Data types (entity types, component names)\n- Formula variables and their bounds\n- Common test scenarios mentioned in Edge Cases\n\nGenerate `tests\/helpers\/[system]_factory.[ext]` with factory functions\nspecific to that system's objects.\n\nExample pattern for a `combat` system (Godot\/GDScript):\n\n```gdscript\n## Factory and assertion helpers for Combat system tests.\n## Generated by \/test-helpers combat on [date].\n## Based on: design\/gdd\/combat.md\n\nclass_name CombatTestFactory\nextends RefCounted\n\nconst DAMAGE_MIN := 0\nconst DAMAGE_MAX := 999  # From GDD: damage formula upper bound\n\n## Create a minimal attacker object for damage formula tests.\nstatic func make_attacker(attack: float = 10.0, crit_chance: float = 0.0) -> Node:\n    var attacker = Node.new()\n    attacker.set_meta(\"attack\", attack)\n    attacker.set_meta(\"crit_chance\", crit_chance)\n    return attacker\n\n## Create a minimal target object for damage receive tests.\nstatic func make_target(defense: float = 0.0, health: float = 100.0) -> Node:\n    var target = Node.new()\n    target.set_meta(\"defense\", defense)\n    target.set_meta(\"health\", health)\n    target.set_meta(\"max_health\", health)\n    return target\n\n## Assert damage output is within GDD-specified bounds.\nstatic func assert_damage_in_bounds(damage: float) -> void:\n    GameAssertions.assert_in_range(damage, DAMAGE_MIN, DAMAGE_MAX, \"damage\")\n```\n\n---\n\n## 6. Write Output\n\nPresent a summary of what will be created:\n\n```\n## Test Helpers to Create\n\nBase helpers (engine: [engine], helper root: [helper root]):\n- [helper root]\/game_assertions.[ext]\n- [helper root]\/game_factory.[ext]\n[engine-specific extras]\n\nSystem helpers ([mode]):\n- [helper root]\/[system]_factory.[ext]  \u2190 from [system] GDD\n```\n\nAsk: \"May I write these helper files to `[helper root]`?\"\n\n**Never overwrite existing files.** If a file already exists, report:\n\"Skipping `[path]` \u2014 already exists. Remove the file manually if you want it\nregenerated.\"\n\nAfter writing: Verdict: **COMPLETE** \u2014 helper files created.\n\n\"Helper files created. To use them in a test:\n- Godot: `class_name` is auto-imported \u2014 no explicit import needed\n- Unity: Add `using` directive or reference the test assembly\n- Unreal: `#include \\\"Tests\/Helpers\/GameTestHelpers.h\\\"` (from inside the module)\"\n\n---\n\n## Collaborative Protocol\n\n- **Never overwrite existing helpers** \u2014 they may contain hand-written\n  customisations. Only generate new files that don't exist yet\n- **Generated code is a starting point** \u2014 the generated factory functions use\n  metadata patterns for simplicity; adapt to the actual class structure once\n  the code exists\n- **Helpers should reflect the GDD** \u2014 bounds and constants in helpers should\n  trace to GDD Formulas sections, not invented values\n- **Ask before writing** \u2014 always confirm before creating files in `tests\/`\n\n## Next Steps\n\n- Run `\/test-setup` if the test framework has not been scaffolded yet.\n- Use `\/dev-story` to implement stories \u2014 helpers reduce boilerplate in new test files.\n- Run `\/skill-test` to validate other skills that may need helper coverage.\n","use_cases":["Generate test helpers for a specific system like 'combat' or 'inventory'","Create base helper library for all systems with test files","Generate only the base helper library on first run"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/Donchitos\/Claude-Code-Game-Studios\/blob\/abc0de79d6ceb0b5d7aa693945849b3937afbe6a\/.claude\/skills\/test-helpers\/SKILL.md","source_commit":"abc0de79d6ceb0b5d7aa693945849b3937afbe6a","license":null,"version":null,"listing_approved_at":"2026-11-18","created_at":"2026-11-17T20:59:50.000000Z","updated_at":"2026-11-18T18:54:36.000000Z","seo_title":"Generate Engine-Specific Test Helpers for Assertion Utilities, Factory","seo_description":"Create engine-specific test helpers for assertion utilities, factory functions, and mocks. Helpers are generated based on the project's test framework and must not use GD","seo_keywords":["generate test helpers","engine-specific assertions","test framework helpers","test boilerplate reduction","test helper generation"]}}