Exemplo n.º 1
0
 public static ResultDTO CreateTestFinished(TestResult test)
 {
     var dto = new ResultDTO(MessageType.TestFinished);
     dto.testName = test.FullName;
     dto.testResult = GetSerializableTestResult(test);
     return dto;
 }
Exemplo n.º 2
0
 public static ResultDTO CreateTestStarted(TestResult test)
 {
     var dto = new ResultDTO(MessageType.TestStarted);
     dto.testName = test.FullName;
     dto.testTimeout = test.TestComponent.timeout;
     return dto;
 }
Exemplo n.º 3
0
		public TestResult AddTest ()
		{
			var go = new GameObject ();
			go.name = "New Test";
			go.AddComponent<TestComponent>();
			ShowTestInHierarchy (go, true);

			var testResult = new TestResult (go);
			testList.Add(testResult);
			SortTestList ();	

			return testResult;
		}
		public TestResult AddTest ()
		{
			var go = new GameObject ();
			go.name = "New Test";
			go.AddComponent<TestComponent>();
			go.transform.hideFlags |= HideFlags.HideInInspector;

			var testResult = new TestResult (go);
			testList.Add(testResult);
			SortTestList ();	

			return testResult;
		}
Exemplo n.º 5
0
        private static ITestResult GetSerializableTestResult(TestResult test)
        {
            var str = new SerializableTestResult();

            str.resultState = test.ResultState;
            str.message = test.messages;
            str.executed = test.Executed;
            str.name = test.Name;
            str.fullName = test.FullName;
            str.id = test.id;
            str.isSuccess = test.IsSuccess;
            str.duration = test.duration;
            str.stackTrace = test.stacktrace;

            return str;
        }
Exemplo n.º 6
0
		public static Texture GetIconForResult ( TestResult.ResultType resultState )
		{
			switch (resultState)
			{
				case TestResult.ResultType.Success:
					return Icons.successImg;
				case TestResult.ResultType.Timeout:
				case TestResult.ResultType.Failed:
				case TestResult.ResultType.FailedException:
					return Icons.failImg;
				case TestResult.ResultType.Ignored:
					return Icons.ignoreImg;
				case TestResult.ResultType.NotRun:
				default:
					return Icons.unknownImg;
			}
		}
			public void TestStarted (TestResult test)
			{
				if (integrationTestRunnerWindow.renderer.blockUIWhenRunning
					&& EditorUtility.DisplayCancelableProgressBar("Integration Test Runner",
																"Running " + test.go.name,
																(float) currentTestNumber / testNumber))
				{
					integrationTestRunnerWindow.isRunning = false;
					EditorApplication.isPlaying = false;
				}

				integrationTestRunnerWindow.renderer.UpdateResults (new List<TestResult> {test});
				integrationTestRunnerWindow.Repaint();
			}
 public IntegrationTestLine(GameObject gameObject, TestResult testResult)
     : base(gameObject)
 {
     m_Result = testResult;
 }
Exemplo n.º 9
0
 public void TestFinished(TestResult test)
 {
     SendDTO(ResultDTO.CreateTestFinished(test));
 }
 public void TestStarted(TestResult test)
 {
     m_Window.SetCurrentTest(test.TestComponent);
     m_CurrentTest = test.TestComponent;
 }
		private void RemoveTest (TestResult test)
		{
			var testsToDelete = new List<TestResult> { test };
			if (selectedTests.Count > 1)
				testsToDelete = selectedTests;

			foreach (var t in testsToDelete)
			{
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
				Undo.RegisterSceneUndo ("Destroy Tests");
				GameObject.DestroyImmediate (t.TestComponent.gameObject);
#else
				Undo.DestroyObjectImmediate (t.TestComponent.gameObject);
#endif
			}

			TestManager.InvalidateTestList ();
			selectedTests.Clear ();
			forceRepaint = true;
		}
Exemplo n.º 12
0
 private void FinishTest(TestResult.ResultType result)
 {
     m_TestsProvider.FinishTest(currentTest);
     var testResult = m_ResultList.Single(t => t.GameObject == currentTest.gameObject);
     testResult.resultType = result;
     testResult.duration = Time.time - m_StartTime;
     testResult.messages = m_TestMessages;
     testResult.stacktrace = m_Stacktrace;
     TestRunnerCallback.TestFinished(testResult);
     currentTest = null;
     if (!testResult.IsSuccess
         && testResult.Executed
         && !testResult.IsIgnored) k_ResultRenderer.AddResults(Application.loadedLevelName, testResult);
 }
		private bool DrawTestGroup ( TestResult testInfo, int indent )
		{
			EditorGUILayout.BeginHorizontal ();
			GUILayout.Space (--indent * 15);
			EditorGUIUtility.SetIconSize (new Vector2 (15, 15));
			Color tempColor = GUI.color;
			if (testInfo.isRunning)
			{
				var frame = Mathf.Abs (Mathf.Cos (Time.realtimeSinceStartup * 4)) * 0.6f + 0.4f;
				GUI.color = new Color (1, 1, 1, frame);
			}

			var label = new GUIContent (testInfo.Name, GetIconBasedOnResultType (testInfo).image);
			var labelRect = GUILayoutUtility.GetRect (label, EditorStyles.label, GUILayout.ExpandWidth (true));

			if (labelRect.Contains (Event.current.mousePosition)
				&& Event.current.type == EventType.MouseDown
				&& Event.current.button == 0)
			{
				SelectTest (testInfo);
			}
			else if (labelRect.Contains (Event.current.mousePosition)
					&& Event.current.type == EventType.ContextClick)
			{
				Event.current.Use ();
				DrawContextTestMenu (testInfo);
			}
			
			bool isClassFolded = foldedGroups.Contains (testInfo);
			EditorGUI.BeginChangeCheck ();
			isClassFolded = !EditorGUI.Foldout (labelRect, !isClassFolded, label
												,selectedTests.Contains (testInfo) ? Styles.selectedTestGroupStyle : Styles.testGroupStyle
								);
			if (EditorGUI.EndChangeCheck ())
			{
				if (isClassFolded)
					foldedGroups.Add (testInfo);
				else
					foldedGroups.Remove (testInfo);
			}

			if (testInfo.isRunning) GUI.color = tempColor;
			EditorGUIUtility.SetIconSize (Vector2.zero);

			if (testInfo.resultType == TestResult.ResultType.Timeout)
			{
				GUILayout.Label (guiTimeoutIcon,
								GUILayout.Width (24)
								);
				GUILayout.FlexibleSpace ();
			}

			EditorGUILayout.EndHorizontal ();
			return !isClassFolded;
		}
		private GUIContent GetIconBasedOnResultType (TestResult result)
		{
			if (result == null) 
				return Icons.guiUnknownImg;
			
			if (result.TestComponent.IsTestGroup ())
			{
				var childrenResults = testManager.GetChildrenTestsResults (result.TestComponent);
				if (childrenResults.Any (t => t.resultType == TestResult.ResultType.Failed 
											|| t.resultType == TestResult.ResultType.FailedException
											|| t.resultType == TestResult.ResultType.Timeout))
					result.resultType = TestResult.ResultType.Failed;
				else if (childrenResults.Any (t => t.resultType == TestResult.ResultType.Success))
					result.resultType = TestResult.ResultType.Success;
				else if (childrenResults.All (t => t.TestComponent.ignored))
					result.resultType = TestResult.ResultType.Ignored;
				else
					result.resultType = TestResult.ResultType.NotRun;

				result.isRunning = childrenResults.Any (t => t.isRunning);
			}		

			if (result.isRunning)
				return Icons.guiUnknownImg;

			if (result.resultType == TestResult.ResultType.NotRun
				&& result.TestComponent.ignored)
				return Icons.guiIgnoreImg;

			switch (result.resultType)
			{
				case TestResult.ResultType.Success:
					return Icons.guiSuccessImg;
				case TestResult.ResultType.Timeout:
				case TestResult.ResultType.Failed:
				case TestResult.ResultType.FailedException:
					return Icons.guiFailImg;
				case TestResult.ResultType.Ignored:
					return Icons.guiIgnoreImg;
				case TestResult.ResultType.NotRun:
				default:
					return Icons.guiUnknownImg;
			}
		}
		private GUIContent GetIconBasedOnResultType (TestResult result)
		{
			if (result == null) return Icons.guiUnknownImg;
			if (result.isRunning)
			{
				return Icons.GetSpinningIcon ();
			}

			if (result.resultType == TestResult.ResultType.NotRun
				&& result.TestComponent.ignored)
				return Icons.guiIgnoreImg;

			switch (result.resultType)
			{
				case TestResult.ResultType.Success:
					return Icons.guiSuccessImg;
				case TestResult.ResultType.Timeout:
				case TestResult.ResultType.Failed:
				case TestResult.ResultType.FailedException:
					return Icons.guiFailImg;
				case TestResult.ResultType.Ignored:
					return Icons.guiIgnoreImg;
				case TestResult.ResultType.NotRun:
				default:
					return Icons.guiUnknownImg;
			}
		}
Exemplo n.º 16
0
		private void FinishTest(TestResult.ResultType result)
		{
			testsProvider.FinishTest (currentTest);
			var testResult = testToRun.Single (t => t.isRunning);
			testResult.resultType = result;
			testResult.isRunning = false;
			testResult.duration = Time.time - startTime;
			testResult.messages = testMessages;
			testResult.stacktrace = stacktrace;
			TestRunnerCallback.TestFinished (testResult);
			currentTest = null;
			if (!testResult.IsSuccess 
				&& testResult.Executed
				&& !testResult.IsIgnored) resultRenderer.AddResults (Application.loadedLevelName, testResult);
		}
		private void RemoveTest (TestResult test)
		{
			var testsToDelete = new List<TestResult> { test };
			if (selectedTests.Count > 1)
				testsToDelete = selectedTests;

			if (EditorUtility.DisplayDialog ("",
											"Are you sure you want to delete " + 
											((testsToDelete.Count > 1) ? (testsToDelete.Count + " tests?"):(testsToDelete.Single().name + "?")),
											"Delete",
											"Cancel"))
			{
				foreach (var t in testsToDelete)
				{	
#if !UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2
					Undo.DestroyObjectImmediate ((t as TestResult).go);
#else
					Undo.RegisterSceneUndo ("Destroy Objects");
					GameObject.DestroyImmediate (t.go);
#endif
				}

				testManager.DeleteTest(testsToDelete);
				selectedTests.Clear ();
				forceRepaint = true;
			}
		}
Exemplo n.º 18
0
		public IEnumerable<TestResult> GetTestsToSelect (List<TestResult> selectedTests, TestResult testToSelect)
		{
			TestResult start = null;
			TestResult end = null;

			for (int i = testList.Count-1; i >=0 ; i--)
			{
				var testResult = testList[i];
				if (start==null)
				{
					if (testResult == testToSelect)
						start = testToSelect;
					else if (selectedTests.Contains (testResult))
						start = testResult;
				}else if(testResult == testToSelect)
				{
					end = testToSelect;
					break;
				}
				if(start!=null)
				{
					if (testResult == testToSelect)
						end = testToSelect;
					else if (selectedTests.Contains(testResult))
						end = testResult;

				}
			}
			var startIdx = testList.IndexOf (start);
			var endIdx = testList.IndexOf (end);
			return testList.GetRange(endIdx, startIdx-endIdx+1);
		}
Exemplo n.º 19
0
		public void SelectInHierarchy (TestResult test)
		{
			foreach (var t in GetAllTestsResults ())
			{
				if (t.GameObject == null)
				{
					InvalidateTestList ();
					continue;
				}
				t.TestComponent.EnableTest (test == t);
				if (t.GameObject.GetComponentsInChildren<TestComponent> (true).Any (c => c == test.TestComponent))
				{
					t.TestComponent.EnableTest (true);
				}
			}
		}
			public void TestFinished (TestResult test)
			{
				currentTestNumber++;
				integrationTestRunnerWindow.renderer.UpdateResults(new List<TestResult> { test });
				integrationTestRunnerWindow.Repaint();
			}
Exemplo n.º 21
0
		private void StartNewTest ()
		{
			this.testMessages = "";
			this.stacktrace = "";
			testState = TestState.Running;
			assertionsToCheck = null;

			startTime = Time.time;
			currentTest = testToRunQueue.Dequeue ();
			currentTest.isRunning = true;
			currentTest.go.SetActive (true);
			
			if (currentTest.TestComponent.succeedAfterAllAssertionsAreExecuted)
				assertionsToCheck = currentTest.go.GetComponentsInChildren<AssertionComponent>().Where(a => a.enabled).ToArray();

			if (currentTest.TestComponent.IsExludedOnThisPlatform ())
			{
				testState = TestState.Ignored;
				Debug.Log(currentTest.name + " is excluded on this platform");
			}

			//do not run ignored tests only when it's batch mode
			//test runner in the editor will not pass ignored tests to run, unless is expected to
			if (!isInitializedByRunner && currentTest.TestComponent.ignored)
				testState = TestState.Ignored;
			LogMessage(startedMessage);
			TestRunnerCallback.TestStarted(currentTest);
		}
		private void SelectTest (TestResult testToSelect)
		{
			if (!Event.current.control && !Event.current.shift)
				selectedTests.Clear();
			if (Event.current.control && selectedTests.Contains (testToSelect))
				selectedTests.Remove (testToSelect);
			else if (Event.current.shift && selectedTests.Any ())
			{
				var tests = testManager.GetTestsToSelect(selectedTests, testToSelect);
				selectedTests.Clear ();
				selectedTests.AddRange (tests);
			}
			else
				selectedTests.Add (testToSelect);
			if (!EditorApplication.isPlayingOrWillChangePlaymode && selectedTests.Count == 1)
			{
				var selectedTest = selectedTests.Single ();
				testManager.SelectInHierarchy(selectedTest);
				EditorApplication.RepaintHierarchyWindow ();
			}
			Selection.objects = selectedTests.Select (result => result.GameObject).ToArray ();
			forceRepaint = true;
			GUI.FocusControl("");
		}
Exemplo n.º 23
0
		private void FinishTest(TestResult.ResultType result)
		{
			testToRun.Find(results => results == currentTest).resultType = result;
			if (currentTest.go!=null)
				currentTest.go.gameObject.SetActive(false);
			currentTest.isRunning = false;
			currentTest.duration = Time.time - startTime;
			currentTest.messages = testMessages;
			currentTest.stacktrace = stacktrace;
			TestRunnerCallback.TestFinished (currentTest);
			currentTest = null;
		}
		private void DrawContextTestMenu (TestResult test)
		{
			if (EditorApplication.isPlayingOrWillChangePlaymode) return;

			var m = new GenericMenu ();
			var localTest = test;
			if(selectedTests.Count > 1)
				m.AddItem(guiRunSelected,
						false,
						data => RunTest(selectedTests.Select (t=>t.TestComponent).ToList ()),
						"");
			m.AddItem (guiRun,
						false,
						data => RunTest(new List<TestComponent> { localTest.TestComponent}),
						"");
			m.AddItem (guiRunAll,
						false,
						data => RunTest (GetVisibleNotIgnoredTests ()),
						"");
			m.AddItem (guiRunAllIncludingIgnored,
						false,
						data => RunTest (GetVisibleTestsIncludingIgnored ()),
						"");
			m.AddSeparator ("");
			m.AddItem (guiDelete,
						false,
						data => RemoveTest (localTest),
						"");

			m.ShowAsContext ();
		}
 public void TestStarted(TestResult test)
 {
     if (window.blockUIWhenRunning
         && EditorUtility.DisplayCancelableProgressBar("Integration Test Runner",
                                                     "Running " + test.Name,
                                                     (float) currentTestNumber / testNumber))
     {
         TestRunInterrupted (null);
     }
 }
		private bool IsNotFiltered (TestResult testInfo)
		{
			if (!testInfo.Name.ToLower ().Contains (filterString.Trim ().ToLower ())) return false;
			if (!showSucceededTest && testInfo.resultType == TestResult.ResultType.Success) return false;
			if (!showFailedTest && (testInfo.resultType == TestResult.ResultType.Failed
				|| testInfo.resultType == TestResult.ResultType.FailedException
				|| testInfo.resultType == TestResult.ResultType.Timeout)) return false;
			if (!showIgnoredTest && (testInfo.resultType == TestResult.ResultType.Ignored || testInfo.TestComponent.ignored)) return false;
			if (!showNotRunnedTest && testInfo.resultType == TestResult.ResultType.NotRun) return false;
			return true;
		}
			public void TestFinished (TestResult test)
			{
				currentTestNumber++;

				var result = window.resultList.Find (r => r.Id == test.Id);
				if(result!=null)
					result.Update (test);
				else
					window.resultList.Add (test);
			}
 private IntegrationTestRendererBase[] ParseTestList(List<TestComponent> testList, List<TestResult> results)
 {
     var tempList = new List<IntegrationTestRendererBase>();
     foreach (var testObject in testList)
     {
         if (!testObject.IsTestGroup())
         {
             var result = new TestResult(testObject);
             if (results != null)
                 results.Add(result);
             tempList.Add(new IntegrationTestLine(testObject.gameObject, result));
             continue;
         }
         var group = new IntegrationTestGroupLine(testObject.gameObject);
         var children = testObject.gameObject.GetComponentsInChildren(typeof(TestComponent), true).Cast<TestComponent>().ToList();
         children = children.Where(c => c.gameObject.transform.parent == testObject.gameObject.transform).ToList();
         group.AddChildren(ParseTestList(children, results));
         tempList.Add(group);
     }
     tempList.Sort();
     return tempList.ToArray();
 }
Exemplo n.º 29
0
 public void TestStarted(TestResult test)
 {
     SendDTO(ResultDTO.CreateTestStarted(test));
 }
            public void TestFinished(TestResult test)
            {
                m_CurrentTestNumber++;

                var result = m_Window.m_ResultList.Find(r => r.Id == test.Id);
                if (result != null)
                    result.Update(test);
                else
                    m_Window.m_ResultList.Add(test);
                    
                if(test.IsFailure && m_Window.m_Settings.pauseOnTestFailure)
                {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.isPaused = true;
                }
            }
Exemplo n.º 31
0
 public void TestStarted(TestResult test)
 {
     m_Window.SetCurrentTest(test.TestComponent);
     m_CurrentTest = test.TestComponent;
 }