ai-agent-unity-rules / rules
Cursor rule40 starsChanged 12 months agoMITView on GitHub
Unity Test Framework (Production Standards)
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository8 other files it gives its agents.
- .cursor/rules/code-organization.mdcCursor rule
- .cursor/rules/unity-architecture.mdcCursor rule
- .cursor/rules/unity-core.mdcCursor rule
- .cursor/rules/unity-ecs.mdcCursor rule
- .cursor/rules/unity-input.mdcCursor rule
- .cursor/rules/unity-networking.mdcCursor rule
- .cursor/rules/unity-performance.mdcCursor rule
- .cursor/rules/unity-ui.mdcCursor rule
The file
We split this unity-testing.mdc into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
When writing tests in Unity 6.2, adhere to the AAA (Arrange, Act, Assert) pattern and use the Constraint Model for assertions (Assert.That).
- Very specific: line 11
Ensure your test script is located in a folder with an .asmdef (Assembly Definition) file that:
- Distinctive: line 16
Use this for testing logic that is independent of the Engine Loop (e.g., Math, Data Parsing, State Machines).
- Distinctive: line 41
Use this for testing GameObject interactions, Physics, and Coroutines.
- Very specific: line 42
IMPORTANT: Always use [TearDown] to destroy created objects.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Unity Test Framework (Production Standards)"
alwaysApply: false
---
# 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));
}
}
```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
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.

