public static void RunTests(TestRunMode testMode) { UnityEngine.Debug.Log("Started running test"); System.Reflection.Assembly[] assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); System.Reflection.Assembly assembly = assemblies.FirstOrDefault(assemblyName => assemblyName.GetName().Name.Equals("Assembly-CSharp-Editor")); var filters = AddTestToBeRun(testMode); NUnit.Framework.Interfaces.ITestListener listener = new TestRunListener(CallRunDelegate); var testAssemblyRunner = new NUnit.Framework.Api.NUnitTestAssemblyRunner(new NUnit.Framework.Api.DefaultTestAssemblyBuilder()); testAssemblyRunner.Load(assembly, new System.Collections.Generic.Dictionary <string, object>()); progress = 0; total = filters.Filters.Count; System.Threading.Thread runTestThread = new System.Threading.Thread(() => { var result = testAssemblyRunner.Run(listener, filters); SetTestStatus(result); AltUnityTesterEditor.isTestRunResultAvailable = true; AltUnityTesterEditor.selectedTest = -1; }); runTestThread.Start(); if (AltUnityTesterEditor.EditorConfiguration.platform != Platform.Editor) { float previousProgres = progress - 1; while (runTestThread.IsAlive) { if (previousProgres == progress) { continue; } UnityEditor.EditorUtility.DisplayProgressBar(progress == total ? "This may take a few seconds" : _testName, progress + "/" + total, progress / total); previousProgres = progress; } } runTestThread.Join(); if (AltUnityTesterEditor.EditorConfiguration.platform != Platform.Editor) { AltUnityTesterEditor.needsRepaiting = true; UnityEditor.EditorUtility.ClearProgressBar(); } }
private static NUnit.Framework.Internal.Filters.OrFilter AddTestToBeRun(TestRunMode testMode) { NUnit.Framework.Internal.Filters.OrFilter filter = new NUnit.Framework.Internal.Filters.OrFilter(); switch (testMode) { case TestRunMode.RunAllTest: foreach (var test in AltUnityTesterEditor.EditorConfiguration.MyTests) { if (!test.IsSuite) { filter.Add(new NUnit.Framework.Internal.Filters.FullNameFilter(test.TestName)); } } break; case TestRunMode.RunSelectedTest: foreach (var test in AltUnityTesterEditor.EditorConfiguration.MyTests) { if (test.Selected && !test.IsSuite) { filter.Add(new NUnit.Framework.Internal.Filters.FullNameFilter(test.TestName)); } } break; case TestRunMode.RunFailedTest: foreach (var test in AltUnityTesterEditor.EditorConfiguration.MyTests) { if (test.Status == -1 && !test.IsSuite) { filter.Add(new NUnit.Framework.Internal.Filters.FullNameFilter(test.TestName)); } } break; } return(filter); }