Failing fast in builds: How can I cancel test run when a test has failed with label 'Error'

Hello, I would like my test run to cancel once a test has failed with an error, like a NullReferenceException, what would be a good way to do that for both editor and builds, most importantly builds?

I found the UnityTestExecutionContext.StopOnError which sounds perfect but it doesn’t seem to be used anywhere and I also don’t know how I would set it without embedding the package.

I could try to use PlaymodeTestsController.TryCleanup with reflection but perhaps there’s a better way?

Update:

  • I’m on 1.3.4
  • I experimented with calling PlaymodeTestsController.Cleanup since that calls StopRun but now I don’t get the RunFinished : ITestRunCallback anymore, probably because there’s a NullReferenceException in PlaymodeTestsController.TestRunnerCoroutine a couple of frames after I have called Cleanup.

Update:

  • On 1.3.4, I embedded the package and removed the m_Runner = null line in PlaymodeTestsController. Calling the Cleanup method now does exactly what I want when TestFinished : ITestRunCallback detects a failed test with label “Error”

Update:

  • I didn’t use reflection. Instead, an Assembly Definition Reference.) was created with a tiny script that calls on the PlaymodeTestsController