Unit Testing

You can write unit tests for Unity using the NUnit framework. This allows you to automate testing and ensure the stability and quality of your project.

To learn more about unit testing in Unity, see the Unity Documentation.

Test types

Unity supports two main test types:

  • Edit Mode tests for pure C# logic that run without entering Play Mode.
  • Play Mode tests for behavior that requires the Unity runtime.

Buildalon workflows can run both Edit Mode and Play Mode tests as separate Unity steps.

Adding Unit Tests to Your Workflow

1. Run Unit Tests

Add either or both steps after Project Validation in your build workflow. Do not pass -quit: the Unity Test Framework exits after the run, while -quit can terminate the editor before results are written. Always provide -testResults so CI has a deterministic XML output path.

- uses: buildalon/unity-action@v3
  name: ${{ matrix.build-target }}-Editor-Tests
  with:
    build-target: ${{ matrix.build-target }}
    args: '-runTests -batchmode -testPlatform EditMode -testResults "${{ github.workspace }}/Logs/EditMode-test-results.xml"'
    log-name: EditMode-Tests

- uses: buildalon/unity-action@v3
  name: ${{ matrix.build-target }}-PlayMode-Tests
  with:
    build-target: ${{ matrix.build-target }}
    args: '-runTests -batchmode -testPlatform PlayMode -testResults "${{ github.workspace }}/Logs/${{ matrix.build-target }}-test-results.xml"'
    log-name: ${{ matrix.build-target }}-Tests

See the full list of command line options in the Unity Documentation.

Best practices

  • Keep tests small and deterministic.
  • Avoid network calls in test code.
  • Write tests for build pipelines and serialization changes.
  • Store test results as artifacts so the team can review failures.

2. Upload Test Results

Upload test results with the diagnostic logs rather than mixing them with build deliverables. These settings preserve results after failed test steps and avoid turning a missing log into a second failure.

- uses: actions/upload-artifact@v7
  name: Upload ${{ matrix.build-target }} Logs
  if: always()
  continue-on-error: true
  with:
    retention-days: 1
    if-no-files-found: ignore
    name: ${{ github.run_number }}.${{ github.run_attempt }}-${{ matrix.build-target }}-Logs
    path: |
      ${{ github.workspace }}/**/*.log
      ${{ github.workspace }}/**/*.xml

3. Review Test Results

Your workflow job will fail if any tests fail. To review the test results, download the test results artifact from the job logs.

Next Steps

  • Triggers: Set up triggers to start workflows automatically.
  • Build Unity: Set up automated builds for your Unity project.
  • Buildalon Actions: Explore the actions available to use in your workflows.
  • Unit Testing: Automate unit testing to ensure stability and quality.
  • Deploy to Stores: Add deployment steps to distribute your app to users.
  • Dependencies: Learn what to do if your project depends on other private packages or repositories.

© 2026 Virtual Maker Corporation