No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlayModeRunTask.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  6. using UnityEngine.TestTools.TestRunner;
  7. namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
  8. {
  9. internal class PlayModeRunTask : TestTaskBase
  10. {
  11. public PlayModeRunTask()
  12. {
  13. SupportsResumingEnumerator = true;
  14. }
  15. public override IEnumerator Execute(TestJobData testJobData)
  16. {
  17. yield return null; // Allow for setting the test job data after a resume.
  18. // Saving of the scene causes serialization of the runner, so the events needs to be resubscribed. This is temporary for now.
  19. // Wait for the active controller
  20. while (PlaymodeTestsController.ActiveController == null)
  21. {
  22. yield return null;
  23. }
  24. var controller = PlaymodeTestsController.ActiveController;
  25. if (controller.m_Runner != null && controller.m_Runner.IsTestComplete)
  26. {
  27. //Already finished, likely zero tests.
  28. testJobData.RunStartedEvent.Invoke(controller.m_Runner.LoadedTest);
  29. testJobData.RunFinishedEvent.Invoke(controller.m_Runner.Result);
  30. yield break;
  31. }
  32. controller.runStartedEvent.AddListener(testJobData.RunStartedEvent.Invoke);
  33. controller.testStartedEvent.AddListener(testJobData.TestStartedEvent.Invoke);
  34. controller.testFinishedEvent.AddListener(testJobData.TestFinishedEvent.Invoke);
  35. controller.runFinishedEvent.AddListener(testJobData.RunFinishedEvent.Invoke);
  36. controller.RunInfrastructureHasRegistered = true;
  37. var runDone = false;
  38. controller.runFinishedEvent.AddListener((_) =>
  39. {
  40. runDone = true;
  41. });
  42. while (!runDone)
  43. {
  44. yield return null;
  45. }
  46. yield return null;
  47. }
  48. }
  49. }