Creating reliable Edit Mode and Play Mode (Runtime) tests for a Match-3 game in Unity is crucial to ensure your game behaves as expected. Below is a comprehensive set of Edit Mode and Runtime (Play Mode) tests tailored to a Match-3 game with:
Unity has a built-in Test Framework (UnityEditor.TestTools, UnityEngine.TestTools) that supports both edit-time and play-mode testing using C# and NUnit.
🛠️ Edit Mode Tests
Edit mode tests should focus on logic that doesn't depend on runtime components like time or UI.
✅ 1. Grid Initialization Test
Verify the grid initializes with the correct dimensions and tile count.
csharp
[Test]
public void GridInitialization_CreatesCorrectNumberOfTiles()
{
var grid = new Match3Grid(12, 12, 6); // Replace with your implementation
int expectedTileCount = 12 * 12;
Assert.AreEqual(expectedTileCount, grid.Tiles.Length);
}
✅ 2. Color Assignment Within Bounds
Check that initial colors are within the expected range (0 to 5 for 6 colors).
csharp
[Test]
public void AllTiles_HaveValidColorIndexes()
{
var grid = new Match3Grid(12, 12, 6);
foreach (var tile in grid.Tiles)
{
Assert.IsTrue(tile.ColorIndex >= 0 && tile.ColorIndex < 6);
}
}
✅ 3. No Automatic Matches on Initialization
In a well-designed match-3 game, the initial board shouldn’t have matches.
csharp
[Test]
public void GridInitialization_HasNoImmediateMatches()
{
var grid = new Match3Grid(12, 12, 6);
var matches = grid.FindMatches();
Assert.IsTrue(matches.Count == 0, "Initial board has matches.");
}
✅ 4. Match Detection Works for Rows and Columns
Test horizontal and vertical match detection.
csharp
[Test]
public void MatchDetection_FindsHorizontalMatches()
{
var grid = new Match3Grid(12, 12, 6);
grid.SetTileColor(0, 0, 2);
grid.SetTileColor(1, 0, 2);
grid.SetTileColor(2, 0, 2);
var matches = grid.FindMatches();
Assert.AreEqual(3, matches.Count);
}
[Test]
public void MatchDetection_FindsVerticalMatches()
{
var grid = new Match3Grid(12, 12, 6);
grid.SetTileColor(0, 0, 4);
grid.SetTileColor(0, 1, 4);
grid.SetTileColor(0, 2, 4);
var matches = grid.FindMatches();
Assert.AreEqual(3, matches.Count);
}
✅ 5. Swap Validity Check
Ensure a swap only occurs if it results in a match.
csharp
[Test]
public void SwapTiles_ResultingInMatch_IsValid()
{
var grid = new Match3Grid(12, 12, 6);
grid.SetTileColor(0, 0, 1);
grid.SetTileColor(1, 0, 1);
grid.SetTileColor(2, 0, 2);
grid.SetTileColor(2, 1, 1); // Swap this
bool isValid = grid.IsValidSwap((2, 0), (2, 1));
Assert.IsTrue(isValid);
}
▶️ Play Mode (Runtime) Tests
Runtime tests simulate actual gameplay — spawning tiles, updating states, handling user interactions.
✅ 1. Swap Executes Properly
Test that a legal swap animates and results in tiles being destroyed.
csharp
[UnityTest]
public IEnumerator Swap_MoveTriggersAnimationAndDestruction()
{
var gameController = GameObject.Instantiate(Resources.Load<GameObject>("GameController")).GetComponent<GameController>();
yield return null; // Wait for initialization
var swapResult = gameController.TrySwapTiles((2, 2), (3, 2));
Assert.IsTrue(swapResult);
yield return new WaitForSeconds(1.5f); // Wait for animations
// Verify that tiles were removed or replaced
Assert.IsTrue(gameController.Grid.GetTile(2, 2).ColorIndex != gameController.Grid.GetTile(3, 2).ColorIndex);
}
✅ 2. Cascading (Chain Reactions) Occur After Matches
If a match causes more matches due to filled tiles, test cascading is handled.
csharp
[UnityTest]
public IEnumerator CascadingMatches_AreResolved()
{
var gameController = GameObject.Instantiate(Resources.Load<GameObject>("GameController")).GetComponent<GameController>();
yield return null;
// Setup initial board manually to ensure cascading
gameController.Grid.SetTileColor(0, 0, 1);
gameController.Grid.SetTileColor(1, 0, 1);
gameController.Grid.SetTileColor(2, 0, 1);
gameController.Grid.SetTileColor(0, 1, 2);
gameController.Grid.SetTileColor(0, 2, 2);
yield return new WaitForSeconds(2.0f);
// After match and fall, check for new matches
var newMatches = gameController.Grid.FindMatches();
Assert.IsTrue(newMatches.Count > 0 || gameController.MatchesClearedCount > 1);
}
✅ 3. Fill Mechanism Works
Ensure empty cells get filled with new tiles after matches.
csharp
[UnityTest]
public IEnumerator EmptyTiles_FilledAfterMatches()
{
var gameController = GameObject.Instantiate(Resources.Load<GameObject>("GameController")).GetComponent<GameController>();
yield return null;
// Create a match
gameController.Grid.SetTileColor(0, 0, 4);
gameController.Grid.SetTileColor(1, 0, 4);
gameController.Grid.SetTileColor(2, 0, 4);
yield return new WaitForSeconds(2.0f); // Wait for match handling
var tile = gameController.Grid.GetTile(0, 0);
Assert.IsNotNull(tile);
Assert.IsTrue(tile.ColorIndex >= 0 && tile.ColorIndex < 6);
}
✅ 4. No Moves Left Detection
Test that the game detects when no valid moves are available.
csharp
[UnityTest]
public IEnumerator NoAvailableMoves_TriggersReshuffle()
{
var gameController = GameObject.Instantiate(Resources.Load<GameObject>("GameController")).GetComponent<GameController>();
yield return null;
gameController.Grid.FillBoardWithNoMovesLeft(); // hypothetical method
bool hasMoves = gameController.Grid.HasAvailableMoves();
Assert.IsFalse(hasMoves);
yield return new WaitForSeconds(1.0f);
Assert.IsTrue(gameController.GridReshuffled); // or equivalent trigger
}
🧪 Recommended Test Tools
NUnit Framework — Already integrated with Unity Tests
Unity Test Framework — Included via com.unity.test-framework
Use [UnityTest] for coroutines and runtime testing
Use ScriptableObjects for configuring test cases (optional)
🧩 Optional: Parameterized Tests
If using NUnit’s [TestCase], you can test different swap positions efficiently.
csharp
[TestCase(0, 0, 1, 0)]
[TestCase(5, 3, 5, 4)]
public void SwapTestCheck(int x1, int y1, int x2, int y2)
{
var grid = new Match3Grid(12, 12, 6);
bool isValid = grid.IsValidSwap((x1, y1), (x2, y2));
Assert.IsInstanceOf<bool>(isValid);
}
Let me know if you’d like me to include mock grid setup utilities, test base classes, or code snippets for grid logic (like FindMatches or IsValidSwap).