|

🧪 Post #3: Testing, Profiling, and Performance Logging in Unity CI

Genesis of Infrastructure — Entry #3
By Emergent Dynamics, building Colonies: Genesis of E.D.E.N.


In the last post, we set up Unity CI to automatically build your project on GitHub.

But simulation games aren’t just about compiling. They’re about behavior — and verifying that systems still produce the correct results under load, over time, and after changes.

Today’s goal:
🎯 Add tests, profiling, and logging hooks to your pipeline, so you can trust every tick of your simulation.


📏 Three Goals of a Simulation-Oriented CI Pipeline

  1. ✅ Validate that the simulation still runs without errors
  2. 🧪 Detect emergent bugs that aren’t caught by compile-time checks
  3. 📉 Measure tick time, execution duration, and behavioral drift over time

🧰 Unity Testing Framework: What You Can Use

Unity provides two test modes:

  • EditMode Tests
  • Run in headless mode, perfect for CI
  • Use for math, logic, simulation determinism
  • PlayMode Tests
  • Use Unity runtime features
  • Requires setup/teardown of test scenes

We’ll focus on EditMode for now — ideal for your Eden.Core simulation layer.


🧪 Step 1: Create a Simulation Test Suite

Create a folder like this:

Assets/External/Eden.Tests/
└── Simulation/
    └── TimeManagerTests.cs

Example test:

using NUnit.Framework;
using Eden.Core.Time;

public class TimeManagerTests
{
    [Test]
    public void AdvanceTime_TickCounterIncrements()
    {
        var manager = new TimeManager();
        float deltaTime = 1.0f;
        manager.Tick(deltaTime);

        Assert.AreEqual(1, manager.CurrentTick);
    }
}

✅ This test will run automatically in CI using Unity’s test runner.


⚙️ Step 2: Enable Tests in CI Workflow

Add this job to your existing unity-ci.yml:

  test:
    name: Run EditMode Tests
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Unity
        uses: game-ci/unity-installer@v3
        with:
          unityVersion: 2021.3.45f1

      - name: Run Unity EditMode tests
        uses: game-ci/unity-test-runner@v3
        with:
          testMode: EditMode

Now your test suite will run every commit and every pull request.


📊 Step 3: Add Performance Profiling Hooks

Inside your simulation systems (e.g., TickManager, WeatherSystem, etc.), add:

using System.Diagnostics;

var stopwatch = Stopwatch.StartNew();
system.Tick(deltaTime);
stopwatch.Stop();

UnityEngine.Debug.Log($"[TickProfiler] {system.GetType().Name} took {stopwatch.ElapsedMilliseconds} ms");

Then, filter logs in CI to extract tick times:

  • Use GitHub Action log search
  • Or add a post-processing step to extract [TickProfiler] lines and save to artifact file

🧱 Recommended Artifact: Performance Report

Update your workflow to upload this:

      - name: Upload performance logs
        uses: actions/upload-artifact@v4
        with:
          name: tick-profiling-report
          path: Logs/tick-performance.log

Store logs per-commit. You now have historical profiling data.


🧠 Why This Matters for Colonies

In a system like Colonies, where time, resource flow, and behavior emerge, the cost of regressions is invisible unless measured.

CI now does that for you.
You are no longer flying blind.


🔁 Summary: Simulation-Aware CI in Unity

Tests validate system correctness
Profiler logs track performance changes
Artifacts create a time machine of system behavior
No human effort required after setup


⏭️ Next Entry: Tracking and Surfacing Errors with CI Dashboards

We’ll explore how to visualize test failures, tick drifts, or memory usage regressions with dashboard integration or GitHub annotations.

You’re now building not just a game — but a fully instrumented simulation platform.

Similar Posts

Leave a Reply