Intro

How to run Unity tests and debug C# code entirely in VS Code without opening Unity’s GUI.

Based on this repo but adapted for Linux (Ubuntu).

  • Node script β†’ automates Unity test runs and result parsing.
  • Unity β†’ executes tests headless, generates XML results.
  • VSCode β†’ attaches the debugger to Unity so breakpoints in test C# code work.
  • Python parser β†’ converts raw Unity XML results into readable output.
  • Benefit: saves CPU and time because Unity Editor doesn’t need to open.

Setup

Setup Overview

  1. Find Unity paths β†’ locate your Unity executable and test folders.
  2. VSCode launch config β†’ lets Node scripts launch Unity and attach debugger automatically.
  3. Debug wait helper β†’ pauses Unity until VSCode attaches.
  4. Node script β†’ runs Unity in batch mode and triggers Python parser.
  5. Python parser β†’ reads Unity XML and prints human-readable Pass/Fail results.
  6. Running tests β†’ how to actually debug and hit breakpoints.

Sample Project Structure

project-root/
β”‚
β”œβ”€β”€ .vscode/
β”‚   └── launch.json
β”‚
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ run-unity-tests.js
β”‚   └── parseUnityTestResults.py
β”‚
β”œβ”€β”€ Assets/                         
β”‚   β”‚
β”‚   β”œβ”€β”€ Scripts/
β”‚   β”‚       β”‚
β”‚   β”‚       └── PlayModeTests/
β”‚   β”‚           └── DodgeballTests.cs
β”‚   β”‚
β”‚   └── ...
β”‚
β”‚
β”œβ”€β”€ TestResults/
β”‚   └── results.xml

1. Find Unity Paths

Purpose: Ensure Unity executable and test scripts are correctly located. Needed so Node script can launch Unity in batch mode and access test assemblies.

  • Find Unity executable path
# Unity executable path (replace with your version)
~/Unity/Editors/6000.0.65f1/Editor/Unity

If you can’t find it, search:

find ~ -name Unity -type f 2>/dev/null

Test that it works:

~/Unity/Editors/6000.0.65f1/Editor/Unity --version

Expected output:

6000.0.65f1

Optional: add Unity to PATH so Node script can call it directly:

echo 'export PATH=$PATH:/home/<your-username>/Unity/Editors/6000.0.65f1/Editor' >> ~/.bashrc
source ~/.bashrc

Verify:

Unity --version

Locate test folders:

ls Assets/Scripts/GameAIStudentWork/EditorModeTests
ls Assets/Scripts/GameAIStudentWork/PlayModeTests

Find test class in a file:

grep -r "class" Assets/Scripts/GameAIStudentWork/PlayModeTests/DodgeballTests.cs
public class DodgeballTests

β€”

2. VSCode Launch Config

Purpose: Configure VSCode to debug Node scripts and attach automatically to Unity. This allows hitting breakpoints in C# test files while Unity runs in batch mode.


3. Add Debug Helpers to Test File

  • Purpose: Makes Unity pause until the debugger is attached, which ensures breakpoints in test scripts actually trigger.
    • Optional: Track time for running tests
  • Add the following near the top of the test file

4. Node Script: run-unity-tests.js

Purpose: Automates running Unity headless, passing environment variables, and invoking the Python parser to format test results.


5. Python Parser

Purpose: Reads Unity test XML and prints a human-readable Pass/Fail summary.

  • Make scripts executable:

6. Running Tests & Hitting Breakpoints

Purpose: Step through Unity test code in VSCode.

  1. Open a PlayMode test file (e.g., PlayModeTests.cs).
  2. Go to Run and Debug (Ctrl+Shift+D).
  3. Select launch config (Test PlayMode).
  4. Click the green debug arrow.

βœ… Node launches Unity headless. Unity pauses at WaitForDebuggerIfRequested(), VSCode attaches, and breakpoints work.


Test Results

Purpose: Quickly see which tests passed or failed without opening Unity GUI.

  • Raw XML: TestResults/GameAIPrisonDodgeball_Spring2026.xml
  • Human-readable output: