UnityGame/Library/PackageCache/com.unity.test-framework/UnityEditor.TestRunner/TestRun/Tasks/PlayModeRunTask.cs

63 lines
2.1 KiB
C#
Raw Normal View History

2024-10-27 10:53:47 +03:00
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestTools.TestRunner;
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
{
internal class PlayModeRunTask : TestTaskBase
{
public PlayModeRunTask()
{
SupportsResumingEnumerator = true;
}
public override IEnumerator Execute(TestJobData testJobData)
{
yield return null; // Allow for setting the test job data after a resume.
// Saving of the scene causes serialization of the runner, so the events needs to be resubscribed. This is temporary for now.
// Wait for the active controller
while (PlaymodeTestsController.ActiveController == null)
{
yield return null;
}
var controller = PlaymodeTestsController.ActiveController;
if (controller.m_Runner != null && controller.m_Runner.IsTestComplete)
{
//Already finished, likely zero tests.
testJobData.RunStartedEvent.Invoke(controller.m_Runner.LoadedTest);
testJobData.RunFinishedEvent.Invoke(controller.m_Runner.Result);
yield break;
}
controller.runStartedEvent.AddListener(testJobData.RunStartedEvent.Invoke);
controller.testStartedEvent.AddListener(testJobData.TestStartedEvent.Invoke);
controller.testFinishedEvent.AddListener(testJobData.TestFinishedEvent.Invoke);
controller.runFinishedEvent.AddListener(testJobData.RunFinishedEvent.Invoke);
controller.RunInfrastructureHasRegistered = true;
var runDone = false;
controller.runFinishedEvent.AddListener((_) =>
{
runDone = true;
});
while (!runDone)
{
if (controller.RaisedException != null)
{
throw controller.RaisedException;
}
yield return null;
}
yield return null;
}
}
}