/unity-coding-skills:run-tests [filter]from unity-coding-skills
Guides running Unity tests via the run_unity_tests tool, including Play Mode tests on standalone players and verifying VisualVerification screenshots. Covers test assembly resolution, domain reload gotchas, and parallel-call restrictions.
Ships in unity-coding-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Guide for running Unity tests with the run_unity_tests tool, running Play Mode tests on a standalone player, and verifying [Category("VisualVerification")] tests from their screenshots.
unity_play_control, get_unity_compilation_result, run_unity_tests, and run_method_in_unity must be called strictly one at a time — always wait for each call to return before making the next one.
Calling them concurrently causes domain-reload conflicts that result in "canceled" or "did not connect within 30 seconds" errors.error or canceled, wait 10 seconds before retrying.
Domain reload typically takes several seconds; immediate retry hits the same in-flight reload and fails again.
Do not switch tools in the meantime (e.g., calling unity_play_control to verify state) — that just compounds the multiplexed calls.
If the same tool returns error or canceled on two consecutive attempts (with the 10-second wait between them), stop and consult the user instead of retrying further.[TestCaseSource] or [ValueSource] enumerates, request a domain reload before running the tests.
The Editor builds the test tree once per domain and reuses it, and an asset import (AssetDatabase.Refresh) does not reload the domain, so the test cases stay as they were at the last reload — a source that found no assets then keeps failing with No arguments were provided.
Call run_method_in_unity with assemblyName: UnityEditor.CoreModule, typeName: UnityEditor.EditorUtility, methodName: RequestScriptReload, then run the tests.Before running tests, complete the following steps in order:
get_unity_compilation_result tool before proceeding.assemblyNames and testMode for a specific test class, run ${CLAUDE_SKILL_DIR}/scripts/resolve_test_target.sh <test-class-cs-path>.
The script prints <assemblyName>\t<testMode> (e.g. MyGame.Tests\tPlayMode).
Skip this step when running an already-known assembly.Then use the run_unity_tests tool to run the tests in the Unity Editor.
Pass groupNames or testNames to select only the tests under verification — the test classes or methods affected by the change.
Run a whole assembly only when the user or the skill that called this one asks for the whole suite or a regression run.
Test execution can take several minutes.
Do not re-run while a test is in progress — always wait for it to complete.
When the call times out, the run may still be in progress in the Unity Editor, so follow ${CLAUDE_SKILL_DIR}/resources/troubleshooting-run-unity-tests.md before running again.
When an open scene has unsaved changes, the Unity Editor shows the "Scene(s) Have Been Modified" dialog, and the run does not start until the dialog is closed; nothing is written to Editor.log meanwhile.
On macOS, start the following command with the Bash tool's run_in_background: true, in the same message as the run_unity_tests call and before it.
The calls in a message run in order, and run_unity_tests does not return until the run ends, so a command placed after it starts too late.
${CLAUDE_SKILL_DIR}/scripts/wait_for_test_run_start.sh <unity-project-root> || osascript ${CLAUDE_SKILL_DIR}/scripts/osx/DiscardCloseSceneHaveBeenModified.applescript
It polls Editor.log every second for up to 20 seconds (the UNITY_RUN_TESTS_DISCARD_SCENE_CHANGES_DELAY_SECONDS environment variable overrides it), and when no test run started by then, it clicks the dialog's "Don't Save" button, which discards the unsaved changes of the scene.
The output is clicked (pid <N>) or not found.
When run_unity_tests returns while the background command is still running, stop it with the TaskStop tool, so that it does not click a dialog that a later action opens.
If the command is denied, run the tests without it.
The tests pass only when none of them fails or is inconclusive: count an inconclusive test as a failure, since its Assume stopped it before it could verify the expected result.
A skipped test does not count as a failure: it is excluded on purpose, e.g., by [Ignore] or a platform condition.
When com.unity.test-framework.performance is installed, each run writes its measurements to PerformanceTestResults.json under Application.persistentDataPath.
Resolve that directory with ${CLAUDE_SKILL_DIR}/scripts/get_persistent_data_path.sh <unity-project-root>.
For the other locations the package writes the file to, and for its measurement pitfalls, see the test-writing-guide skill's resources/unity-test-framework-performance.md.
run_unity_tests runs tests only inside the Unity Editor.
Run tests on a player instead when the user asks for it (e.g., "run on player", "standalone", "実機で実行"), or when player-only behavior must be verified (code inside #if !UNITY_EDITOR, Resources-based loading, IL2CPP, player-build hooks such as ITestPlayerBuildModifier).
Pick the section below by target platform.
For a standalone player running on the host OS (macOS, Windows, or Linux): Read ${CLAUDE_SKILL_DIR}/resources/run-on-standalone-player.md.
It covers the build-and-run procedure and troubleshooting including Player.log locations.
TBD
A test method carrying [Category("VisualVerification")] may have no Assert statements (see test-writing-guide skill), so Passed says nothing about whether the screen actually looks right.
That judgment has to come from analyzing the screenshot the test captured.
Only analyze when the run was to confirm a change made in this session — production code, test code, a scene, a prefab, or another asset. Skip the analysis when nothing is under verification: a regression run over unchanged code, or when the user only asked whether the tests pass.
This applies to Editor runs (run_unity_tests) only.
A standalone-player run writes Temp/PlayerTestResult.txt, not an XML result file (see resources/run-on-standalone-player.md), and on macOS the Player's persistentDataPath differs from the Editor's (see the comment in scripts/get_persistent_data_path.sh).
[TakeScreenshot] itself is Play Mode only.
${CLAUDE_SKILL_DIR}/scripts/extract_visual_verification.sh <unity-project-root>
This prints, per [Category("VisualVerification")] test found in Application.persistentDataPath/TestResults.xml, its NUnit result, its Description property (the verification aspects), and its Screenshot propert(y/ies) (absolute path(s)).
See the script's own comments for why it tokenizes the XML instead of matching lines with grep (class-scoped [Category] lands on the ancestor <test-suite>, not the <test-case>; a test can record more than one Screenshot).TestResults.xml is overwritten on each run, not appended.
Treat the printed age (— N seconds ago) as a secondary signal only; it can't discriminate a stale file from a few minutes ago from a run that legitimately took a few minutes.
On either signal of staleness, stop and report it instead of analyzing.result is Passed, read the image(s) at its Screenshot path(s) and judge them against the aspects listed in Description.
Report each aspect's verdict with what you actually saw in the image.result is not Passed, do not analyze — report it as a failure instead (the screenshot, if any, may be from a partial run).Whether TestResults.xml is written under persistentDataPath depends on the project (e.g., the com.unity.test-framework.performance package's RunFinished callback writes it).
If it is absent, fall back:
[TakeScreenshot]/ScreenshotHelper log Save screenshot to <absolute path> on every capture.
Find the current log file (compare mtimes of Editor.log and Editor-prev.log — see resources/troubleshooting-run-unity-tests.md → "Editor.log vs Editor-prev.log"), then take the Save screenshot to lines that appear after the last - Finished resetting the current domain line (the lifecycle marker for the run you just triggered — same resource, "Tests launched but timed out" table).[Description(...)] attribute directly from the test's source file.${CLAUDE_SKILL_DIR}/scripts/get_persistent_data_path.sh <unity-project-root> prints the Editor's Application.persistentDataPath for the current OS (from companyName/productName in ProjectSettings/ProjectSettings.asset, per Unity's docs).
extract_visual_verification.sh calls it automatically; use it directly only when you need the raw directory.
If the same test(s) fail on two or more consecutive runs, stop and consult the user rather than continuing to fix.
When consulting, clarify:
Read the appropriate resource file based on the situation:
run_unity_tests, unity_play_control, get_unity_compilation_result) is not available or fails with a connection error, or run_unity_tests times out: Read ${CLAUDE_SKILL_DIR}/resources/troubleshooting-run-unity-tests.mdTestHelper namespace (excluding TestHelper.UI): Read ${CLAUDE_SKILL_DIR}/resources/troubleshooting-test-helper.mdTestHelper.UI namespace: Read ${CLAUDE_SKILL_DIR}/resources/troubleshooting-test-helper-ui.mdassets/PlayerTestRunner.cs (opens in a new tab)resources/run-on-standalone-player.md (opens in a new tab)resources/troubleshooting-run-unity-tests.md (opens in a new tab)resources/troubleshooting-test-helper-ui.md (opens in a new tab)resources/troubleshooting-test-helper.md (opens in a new tab)scripts/extract_visual_verification.sh (opens in a new tab)scripts/get_persistent_data_path.sh (opens in a new tab)scripts/get_player_settings.sh (opens in a new tab)scripts/osx/DiscardCloseSceneHaveBeenModified.applescript (opens in a new tab)scripts/resolve_assembly.sh (opens in a new tab)scripts/resolve_test_target.sh (opens in a new tab)scripts/wait_for_test_run_start.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub nowsprinting/unity-coding-skills --plugin unity-coding-skills12 skills in this plugin
/code-writing-guideProvides coding guidelines for Unity projects. Make sure to use this skill whenever writing, creating, editing, or modifying code files. This includes implementing new features, fixing bugs, refactoring, adding tests, or any task that results in code changes. Even for small edits or one-line fixes, load this skill to ensure project conventions are followed./design-testsDesigns tests from a specification, whatever document states it — a requirements document, design docs, or an ADR: extracts the test targets, then creates test cases for each target at the test level of its subject — e.g., integration tests for a scene or prefab, unit tests for a class's API. Use this skill whenever the specification is settled and the next step is to design the tests./edit-sceneCreates and modifies Unity scene and prefab files. Use this skill whenever creating, editing, or modifying .unity scene files or .prefab prefab files. This includes adding GameObjects, building uGUI hierarchies, wiring up components, and any task that results in changes to .unity or .prefab files./find-and-setup-analysis-ruleFinds an analysis rule that flags a given coding pattern — a Roslyn analyzer package, an IDE inspection, an IDE plugin, or a custom Roslyn analyzer — and sets it up in the Unity project at `warning` or higher severity. Use this skill when the user wants a coding pattern flagged as the code is written, e.g., to keep a fixed bug from recurring, to ban an API, to cap method complexity, or to enforce a coding rule. Also use it when the user wants a named Roslyn analyzer package installed in the Unity project./fix-bugDiagnoses and fixes bugs using a test-first workflow (reproduce, diagnose, fix). Use this skill whenever the user reports a bug, describes unexpected behavior, or asks to investigate or fix a defect./implementImplements a feature or a specification change test-first, phase by phase from the parts with no dependencies up: each phase designs its missing test cases, then writes failing tests and the production code that passes them. Use this skill whenever the user asks to implement or add a feature, or to change an existing specification.Other plugins' skills for the same job