Loading lessons...
Unity Properties & Test Framework
Unity Properties & Test Framework
To build clean, reliable games, you need structures to handle data binding and tools to verify script correctness automatically.
Unity Properties
Unity Properties is a data-binding and serialization framework:
- It allows you to define properties on your classes that can be automatically animated, serialized, or bound to UI Toolkit controls.
- Useful for keeping game logic decoupled from UI render updates.
Unity Test Framework
The Unity Test Framework (UTF) allows you to write and run tests inside the Editor:
- Based on NUnit, it supports both EditMode and PlayMode tests.
- EditMode Tests: Test script logic, mathematical functions, and asset parsing. These run instantly without launching player loops.
- PlayMode Tests: Test behaviors, physics, and gameplay actions. These run inside a temporary player window, letting you instantiate GameObjects and yield time.
[Test]
public void PlayerHealth_UnderDamage_DecreasesValue()
{
var health = new Health(100);
health.TakeDamage(20);
Assert.AreEqual(80, health.CurrentHealth);
}
TL;DR
- Unity Properties bind class fields directly to UI and serialization systems.
- Unity Test Framework runs automated test scripts within the Unity Editor.
- EditMode tests evaluate raw script logic without starting the game loop.
- PlayMode tests let you instantiate prefabs and evaluate real-time physics.