public static void StartTestRun (string[] testsToRunList, ITestRunnerCallback eventListener, bool performUndo)
		{
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
			if (performUndo)
				Undo.RegisterSceneUndo ("UnitTestRunSceneSave");
#else
			var undoGroup = Undo.GetCurrentGroup ();
#endif
			var callbackList = new TestRunnerCallbackList ();
			if (eventListener != null) callbackList.Add (eventListener);
			try
			{
				foreach (var unitTestEngine in TestEngines)
				{
					unitTestEngine.RunTests (testsToRunList, callbackList);
				}
			}
			catch (Exception e)
			{
				Debug.LogException (e);
				callbackList.RunFinishedException (e);
			}
			finally
			{
				if (performUndo)
				{
					var undoStartTime = DateTime.Now;
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
					Undo.PerformUndo ();
#else
					Undo.RevertAllDownToGroup (undoGroup);
#endif
					if ((DateTime.Now - undoStartTime).Seconds > 1)
						Debug.LogWarning ("Undo after unit test run took " + (DateTime.Now - undoStartTime).Seconds + " seconds. Consider running unit tests on a new scene for better performance.");
				}
				EditorUtility.ClearProgressBar ();
				if (UnityEditorInternal.InternalEditorUtility.inBatchMode)
					EditorApplication.Exit (0);
			}
		}
Exemple #2
0
 public void StartTestRun(TestFilter filter, ITestRunnerCallback eventListener)
 {
     var callbackList = new TestRunnerCallbackList();
     if (eventListener != null) callbackList.Add(eventListener);
     k_TestEngine.RunTests(filter, callbackList);
 }
		private void StartTestRun ()
		{
			var okToRun = true;
			if (runTestOnANewScene && !UnityEditorInternal.InternalEditorUtility.inBatchMode)
			{
				if (autoSaveSceneBeforeRun)
					EditorApplication.SaveScene ();
				okToRun = EditorApplication.SaveCurrentSceneIfUserWantsTo ();
			}
			if (okToRun)
			{
				var currentScene = EditorApplication.currentScene;
				if (runTestOnANewScene || UnityEditorInternal.InternalEditorUtility.inBatchMode)
					EditorApplication.NewScene ();
				var callbackList = new TestRunnerCallbackList ();
				callbackList.Add (new TestRunnerEventListener (this));
				try
				{
					foreach (var unitTestEngine in testEngines)
					{
						unitTestEngine.RunTests (testsToRunList,
												callbackList);
					}
				}
				catch (Exception e)
				{
					Debug.LogException (e);
					callbackList.RunFinishedException (e);
				}
				finally
				{
					EditorUtility.ClearProgressBar();
					if (runTestOnANewScene && !UnityEditorInternal.InternalEditorUtility.inBatchMode)
						EditorApplication.OpenScene (currentScene);
					if (UnityEditorInternal.InternalEditorUtility.inBatchMode)
						EditorApplication.Exit(0);
					shouldUpdateTestList = true;
				}
			}
		}