agentleFS
skysepehruskysepehru/unity-claude-skills/skills/unity-testing/SKILL.md

unity-testing

Skill1 starsChanged 5 months agoMITView on GitHub

Guide for testing Unity applications. Covers Unity Test Framework, what's testable vs requires human validation, and Zenject testing patterns.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Rule of thumb: No MonoBehaviour lifecycle needed and no timing → Edit Mode.

    line 22
  2. Distinctive:

    Use MCP tools to run tests and read failure details — not the Unity Editor test runner UI.

    line 117

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Unity Testing Guide

Testing reference for Unity projects using Zenject.


Edit Mode vs Play Mode

Use Edit Mode when...Use Play Mode when...
Pure logic, calculations, data transformsNeeds Start(), Update(), or other lifecycle
State machines, service logicCoroutines or async operations
Event wiring (subscribe/fire/assert)Physics, scene loading
Anything without MonoBehaviour dependencyTime-based behavior (timers, cooldowns)
Multi-system integration through full container

Rule of thumb: No MonoBehaviour lifecycle needed and no timing → Edit Mode. Otherwise → Play Mode.


Testable vs Human Validation

Testable (automated)Human validation (manual)
Logic and calculationsVisual appearance
State transitionsAnimation feel
Event wiring and callbacksGame feel / fun
Data transformationsAudio quality
Service interactionsInput responsiveness on device
Boundary conditions (min/max/zero)Performance / frame rate

Design principle: Keep logic separate from visuals. A service that computes results is trivially testable. A MonoBehaviour that displays those results requires manual validation. The more logic lives in injectable services, the more you can test automatically. Test the public interface — how the class will actually be used — not its internals.


Zenject Test Fixtures

ZenjectUnitTestFixture (Edit Mode)

Isolated DI container per test. Bind only what you need.

using NUnit.Framework;
using Zenject;

public class ScoreServiceTests : ZenjectUnitTestFixture
{
    [Inject] private ScoreService _scoreService;

    [SetUp]
    public void Setup()
    {
        Container.Bind<ScoreService>().AsSingle();
        Container.Inject(this);
    }

    [Test]
    public void AddScore_IncreasesTotal()
    {
        _scoreService.Add(100);
        Assert.AreEqual(100, _scoreService.Total);
    }
}

ZenjectIntegrationTestFixture (Play Mode)

Full container with MonoBehaviour lifecycle. Use when testing systems that depend on Start().

using System.Collections;
using NUnit.Framework;
using UnityEngine.TestTools;
using Zenject;

public class GameFlowTests : ZenjectIntegrationTestFixture
{
    [UnityTest]
    public IEnumerator GameOver_WhenHPReachesZero()
    {
        PreInstall();
        Container.Bind<HPService>().AsSingle();
        Container.Bind<GameStateService>().AsSingle();
        PostInstall();

        yield return null; // Let Start() execute

        var hp = Container.Resolve<HPService>();
        var state = Container.Resolve<GameStateService>();

        hp.TakeDamage(hp.MaxHP);

        Assert.AreEqual(GameState.Over, state.Current);
    }
}

Pitfalls

  • Injection timing: Dependencies are available in Start(), not Awake(). Tests that create MonoBehaviours must yield return null after setup to let Start() run before asserting.
  • Edit Mode cannot yield: No WaitForSeconds, no coroutines, no frame advancement. If your test needs any of these → Play Mode.
  • Time.deltaTime is zero in Edit Mode: Time-dependent logic must be tested in Play Mode, or accept a time parameter for testability.
  • Project convention — no IInitializable/ITickable/IDisposable: Use MonoBehaviour lifecycle instead. This means integration tests often need Play Mode + yield return null for Start() to fire.
  • PostInstall before resolving: In ZenjectIntegrationTestFixture, always call PostInstall() before resolving or injecting. yield return null after PostInstall for Start().

Running Tests

Use MCP tools to run tests and read failure details — not the Unity Editor test runner UI.


References (don't duplicate — look here instead)

  • Test file locations and path mirroring → unity-folder-conventions skill
  • Naming conventions → unity-coding-conventions skill

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.