RiderTestRunner.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using JetBrains.Annotations;
  2. using UnityEngine;
  3. #if TEST_FRAMEWORK
  4. using UnityEditor;
  5. using UnityEditor.TestTools.TestRunner.Api;
  6. #endif
  7. namespace Packages.Rider.Editor.UnitTesting
  8. {
  9. public static class RiderTestRunner
  10. {
  11. #if TEST_FRAMEWORK
  12. private static readonly TestsCallback Callback = ScriptableObject.CreateInstance<TestsCallback>();
  13. #endif
  14. [UsedImplicitly]
  15. public static void RunTests(int testMode, string[] assemblyNames, string[] testNames, string[] categoryNames, string[] groupNames, int? buildTarget)
  16. {
  17. #if !TEST_FRAMEWORK
  18. Debug.LogError("Update Test Framework package to v.1.1.1+ to run tests from Rider.");
  19. #else
  20. CallbackData.instance.isRider = true;
  21. var api = ScriptableObject.CreateInstance<TestRunnerApi>();
  22. var settings = new ExecutionSettings();
  23. var filter = new Filter
  24. {
  25. assemblyNames = assemblyNames,
  26. testNames = testNames,
  27. categoryNames = categoryNames,
  28. groupNames = groupNames,
  29. targetPlatform = (BuildTarget?) buildTarget
  30. };
  31. if (testMode > 0) // for future use - test-framework would allow running both Edit and Play test at once
  32. filter.testMode = (TestMode) testMode;
  33. settings.filters = new []{
  34. filter
  35. };
  36. api.Execute(settings);
  37. api.UnregisterCallbacks(Callback); // avoid multiple registrations
  38. api.RegisterCallbacks(Callback); // This can be used to receive information about when the test suite and individual tests starts and stops. Provide this with a scriptable object implementing ICallbacks
  39. #endif
  40. }
  41. }
  42. }