test-writing-guide

A set of rules for writing tests in Unity, a game-development engine. It covers when to stop Play Mode, how to handle scenes and created objects, how to mark integration or acceptance tests, and how to keep test-only production code out of normal builds.

In plain words
What is it for?
Use it whenever adding, editing, fixing, or expanding files under Unity's Tests directories, including unit, integration, visual-verification, and acceptance tests.
Why use it?
Unity tests have project-specific requirements that can cause editor errors, unwanted files, or tests that behave differently from the finished game. The guide keeps new and changed tests consistent with those requirements.

Skill for Claude CodeCodex

Part of the unity-coding-skills plugin — 10 skills, 3 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/nowsprinting/unity-coding-skills/test-writing-guide
Any agent
npx skills add nowsprinting/unity-coding-skills --skill test-writing-guide
Clone the repo
git clone --depth 1 https://github.com/nowsprinting/unity-coding-skills

Made for: Claude Code, Codex.

Or install unity-coding-skills, the plugin that ships this one along with the rest of its 10 skills, 3 agents.

Per session 81 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,182 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00081 $0.02182
Opus 5 $0.00041 $0.01091
Sonnet 5 $0.00016 $0.00436
Haiku 4.5 $0.00008 $0.00218

Measured 3d ago against content hash 85efcd22fc74, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test-writing-guide scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/create-test-asmdef.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/test-writing-guide/SKILL.md · 135 lines

How it starts

The opening of the file, as written. The whole thing — 135 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Guide for writing test code for Unity projects.

Rules

  • Before modifying any test file, check if the editor is in Play Mode. If it is, stop it using the unity_play_control tool first.
  • Never create .meta files. Unity editor creates them automatically.
  • When a test creates a GameObject or instantiates a prefab, add [CreateScene] to the test method (not required if [LoadScene] is already present).
  • When adding a test seam to production code (e.g., an internal accessor or a virtual override point to support injection), always wrap it with #if UNITY_INCLUDE_TESTS#endif so it is excluded from non-test builds:
    #if UNITY_INCLUDE_TESTS
    internal void SetStateForTest(State state) => _state = state;
    #endif
    

Categories

  • When implementing tests designed as integration tests, add [Category("Integration")] to the test method.
  • When implementing tests designed as visual verification tests, add [Category("VisualVerification")] to the test method.
  • When implementing tests designed as acceptance tests (marked (acceptance test) in the test case design), add [Category("Acceptance")] to the test method.
  • For test methods that test the internal visibility method, add [Category("Internal")].
  • For test methods that depend on animation timing or other timing-sensitive conditions that may cause instability on slow CPUs, add [Category("IgnoreCI")].
  • For test methods that specify the GameViewResolution attribute, add [Category("IgnoreCI")].

Multi-frame tests

When a game mechanic across frames (e.g., playing a card and waiting for its resolution), wait for the step to finish before asserting — not at a fixed frame count.

await DragCard(Cards[1], Enemies[0]);
while (battleDirector.IsPlaying) // wait until the played action fully resolves
    await Awaitable.NextFrameAsync();
Assert.That(battleState.Enemies[0].Hp, Is.LessThan(hpBefore));
  • To confirm step completion, use a production-side state machine or a "busy" signal (IsPlaying, coroutine flag, etc.). Do not use a fixed number of frames or WaitForSeconds.
  • When UniTask is available, UniTask.WaitUntil and UniTask.WaitUntilValueChanged are alternatives to the while loop:
    await UniTask.WaitUntil(() => isActive == false);
    await UniTask.WaitUntilValueChanged(this, x => x.isActive);
    
  • When an operation triggers a deferred Destroy or UI rebuild, advance one extra await Awaitable.NextFrameAsync() before asserting on the new hierarchy.

Read the full file on GitHub · 135 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 135 lines · 81 tokens per session scan A 85efcd22fc74

Subscribe to this mod's changes

test-writing-guide is a skill published in the GitHub repository nowsprinting/unity-coding-skills (19 stars, last pushed 3d ago), licensed Unlicense. It adds 81 tokens to every session and 2,182 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

unity

Compile, test, and drive Unity for this repo's C# packages (unity/core, jint, quickjs, clearscript) and the two Unity projects (tests/, kitchen-sink/). Use when a change touches C# under unity/, when Unity test results are needed, when a rendering snapshot has to be checked or regenerated, or when the app has to be…

ReactUnity/core · 108 tokens

uloop-execute-dynamic-code

Execute C# with Unity APIs when existing uloop tools cannot inspect or edit enough. Use for reachable scene/component state, scene/prefab/menu automation, and PlayMode checks.

hatayama/unity-cli-loop · 43 tokens

uloop-simulate-mouse-input

Simulate Mouse.current input in PlayMode through Unity Input System. Use for gameplay mouse clicks, long-press (LongPress), movement delta (MoveDelta/SmoothDelta), or scroll. Use --dry-run to check what a Game View coordinate hits in 3D physics before clicking (works in EditMode; no Input System required). Use…

hatayama/unity-cli-loop · 113 tokens

uloop-simulate-mouse-ui

Simulate PlayMode EventSystem UI mouse actions using screen coordinates. Use for UI clicks, long-presses, or drags from annotated screenshots.

hatayama/unity-cli-loop · 39 tokens

uloop-pause-point

Pauses Unity playback at any source file:line without editing code or recompiling, and returns a snapshot of the locals, parameters, and instance fields at that exact frame. Use for bug investigation, PlayMode/E2E verification, checking variable values at a specific frame, or confirming that a code path executed.

hatayama/unity-cli-loop · 69 tokens

uloop-screenshot

Capture Unity Editor windows or Game View rendering as PNG. Use for visual checks, debugging, documentation, or annotated UI element coordinates.

hatayama/unity-cli-loop · 31 tokens