unity-testing

A set of rules for testing Unity projects with the Unity Test Framework, including tests for ordinary C# logic and tests that run inside the game.

In plain words
What is it for?
Use it to test calculations, data parsing, state machines, gameplay systems, integration behavior, and physics. It also requires test folders to reference the project and Unity test assemblies.
Why use it?
It provides a consistent way to organize tests and report failures, while keeping fast logic tests separate from tests involving Unity’s engine loop or physics.

Cursor rule for Cursor

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 rules/common-ka/ai-agent-unity-rules/unity-testing
Clone the repo
git clone --depth 1 https://github.com/Common-ka/ai-agent-unity-rules

Made for: Cursor.

Per session 7 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 593 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.00007 $0.00593
Opus 5 $0.00003 $0.00296
Sonnet 5 $0.00001 $0.00119
Haiku 4.5 $0.00001 $0.00059

Measured yesterday against content hash 2a912d84f3a6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unity-testing 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 yesterday.

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.

.cursor/rules/unity-testing.mdc · 93 lines

What it actually says

Unity Test Framework Guidelines

When writing tests in Unity 6.2, adhere to the AAA (Arrange, Act, Assert) pattern and use the Constraint Model for assertions (Assert.That). This ensures readability and maintainability.

1. Assembly Definition Requirement

Ensure your test script is located in a folder with an .asmdef (Assembly Definition) file that:

  1. References UnityEngine.TestRunner and UnityEditor.TestRunner.
  2. References the Assembly Definition of your main project logic (Runtime code).

2. Edit Mode Test (Pure Logic)

Use this for testing logic that is independent of the Engine Loop (e.g., Math, Data Parsing, State Machines). These tests run very fast.

using NUnit.Framework;
// using MyProject.Systems; 

public class HealthSystemTests
{
    [Test]
    public void TakeDamage_DecreasesCurrentHealth()
    {
        // Arrange
        var healthSystem = new HealthSystem(maxHealth: 100);

        // Act
        healthSystem.TakeDamage(30);

        // Assert
        // Use Constraint Model for better readability
        Assert.That(healthSystem.CurrentHealth, Is.EqualTo(70));
    }
}

3. Play Mode Test (Integration & Physics)

Use this for testing GameObject interactions, Physics, and Coroutines. IMPORTANT: Always use [TearDown] to destroy created objects. If you rely on Object.Destroy at the end of the test method and an assertion fails beforehand, the object will leak into the scene.

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

public class PlayerMovementTests
{
    // Standard Microsoft C# style: _camelCase for private fields
    private GameObject _player;
    private PlayerController _controller;

    [SetUp]
    public void Setup()
    {
        // Create an isolated environment for each test
        _player = new GameObject("TestPlayer");
        _controller = _player.AddComponent<PlayerController>();
    }

    [TearDown]
    public void Teardown()
    {
        // Guaranteed cleanup even if an assertion fails
        if (_player != null)
        {
            Object.Destroy(_player);
        }
    }

    [UnityTest]
    public IEnumerator Move_ForwardInput_ChangesPosition()
    {
        // Arrange
        var startPosition = _player.transform.position;
        
        // Act
        _controller.Move(Vector3.forward);
        
        // Wait for one frame (for Update logic)
        yield return null; 
        
        // OR wait for physics step if using Rigidbody
        // yield return new WaitForFixedUpdate(); 
        
        // Assert
        Assert.That(_player.transform.position.z, Is.GreaterThan(startPosition.z));
    }
}
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. yesterday First seen · 93 lines · 7 tokens per session scan A 2a912d84f3a6

Subscribe to this mod's changes

unity-testing is a cursor rule published in the GitHub repository Common-ka/ai-agent-unity-rules (39 stars, last pushed 8mo ago), licensed MIT. It adds 7 tokens to every session and 593 once invoked, about $0.0000 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.