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.

UnityTestProtocolStarter.cs 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEditor.TestTools.TestRunner.Api;
  5. using UnityEngine;
  6. namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
  7. {
  8. [InitializeOnLoad]
  9. internal static class UnityTestProtocolStarter
  10. {
  11. static UnityTestProtocolStarter()
  12. {
  13. var commandLineArgs = Environment.GetCommandLineArgs();
  14. //Ensuring that it is used only when tests are run using UTR.
  15. if (IsEnabled())
  16. {
  17. var api = ScriptableObject.CreateInstance<TestRunnerApi>();
  18. var listener = new UnityTestProtocolListener(GetRepositoryPath(commandLineArgs));
  19. api.RegisterCallbacks(listener);
  20. }
  21. }
  22. internal static bool IsEnabled()
  23. {
  24. var commandLineArgs = Environment.GetCommandLineArgs();
  25. return commandLineArgs.Contains("-automated") && commandLineArgs.Contains("-runTests");
  26. }
  27. private static string GetRepositoryPath(IReadOnlyList<string> commandLineArgs)
  28. {
  29. for (var i = 0; i < commandLineArgs.Count; i++)
  30. {
  31. if (commandLineArgs[i].Equals("-projectRepositoryPath"))
  32. {
  33. return commandLineArgs[i + 1];
  34. }
  35. }
  36. return string.Empty;
  37. }
  38. }
  39. }