public override bool SetCurrentTest(TestComponent tc)
 {
     m_IsRunning = false;
     foreach (var child in m_Children)
         m_IsRunning |= child.SetCurrentTest(tc);
     return m_IsRunning;
 }
		public IList<TestResult> GetChildrenTestsResults ( TestComponent tc )
		{
			TryToReload ();
			if(tc==null)
				return testList.Where (t => t.GameObject != null && t.GameObject.transform.parent == null).ToList ();
			else
				return testList.Where (t => t.GameObject != null && t.GameObject.transform.parent == tc.gameObject.transform).ToList ();
		}
Exemple #3
0
        private void StartNewTest()
        {
            this.testMessages = "";
            this.stacktrace   = "";
            testState         = TestState.Running;
            assertionsToCheck = null;

            startTime   = Time.time;
            currentTest = testsProvider.GetNextTest() as TestComponent;

            var testResult = resultList.Single(result => result.TestComponent == currentTest);

            if (currentTest.ShouldSucceedOnAssertions())
            {
                var assertionList = currentTest.gameObject.GetComponentsInChildren <AssertionComponent> ().Where(a => a.enabled);

                if (assertionList.Any())
                {
                    assertionsToCheck = assertionList.ToArray();
                }
            }

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

            //don't ignore test if user initiated it from the runner and it's the only test that is being run
            if (currentTest.IsIgnored() && !(isInitializedByRunner && resultList.Count == 1))
            {
                testState = TestState.Ignored;
            }

            LogMessage(startedMessage);
            TestRunnerCallback.TestStarted(testResult);
        }
        private static void BackgroundSceneChangeWatch()
        {
            if (!s_Instance)
            {
                return;
            }
#if UNITY_5_3_OR_NEWER
            var currentScene = SceneManager.GetActiveScene().path;
#else
            var currentScene = Application.loadedLevelName;
#endif
            if (s_Instance.m_CurrectSceneName != null && s_Instance.m_CurrectSceneName == currentScene)
            {
                return;
            }
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }
            TestComponent.DestroyAllDynamicTests();
            s_Instance.m_CurrectSceneName = currentScene;
            s_Instance.m_ResultList.Clear();
            s_Instance.RebuildTestList();
        }
        private void RunTests(IList <ITestComponent> tests)
        {
            if (!tests.Any() || EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            FocusWindowIfItsOpen(GetType());

            testsToRun = tests.Where(t => t is TestComponent).Cast <TestComponent> ().ToList();
            var temp = testsToRun.Where(t => t.dynamic).ToArray();

            dynamicTestsToRun = temp.Select(c => c.dynamicTypeName).ToList();
            testsToRun.RemoveAll(temp.Contains);

            readyToRun = true;
            TestComponent.DisableAllTests();
            EditorApplication.isPlaying = true;

            if (blockUIWhenRunning)
            {
                EditorUtility.DisplayProgressBar("Integration Test Runner", "Initializing", 0);
            }
        }
        public override void OnInspectorGUI()
        {
            var component = (TestComponent)target;

            if (component.dynamic && GUILayout.Button("Reload dynamic tests"))
            {
                TestComponent.DestroyAllDynamicTests();
                Selection.objects = new Object[0];
                IntegrationTestsRunnerWindow.selectedInHierarchy = false;
                return;
            }

            if (component.IsTestGroup())
            {
                EditorGUI.BeginChangeCheck();
                var newGroupName = EditorGUILayout.TextField(m_GUITestName, component.name);
                if (EditorGUI.EndChangeCheck())
                {
                    component.name = newGroupName;
                }

                serializedObject.ApplyModifiedProperties();
                return;
            }

            serializedObject.Update();

            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);

            EditorGUI.BeginChangeCheck();
            var newName = EditorGUILayout.TextField(m_GUITestName, component.name);

            if (EditorGUI.EndChangeCheck())
            {
                component.name = newName;
            }

            if (component.platformsToIgnore == null)
            {
                component.platformsToIgnore = GetListOfIgnoredPlatforms(Enum.GetNames(typeof(TestComponent.IncludedPlatforms)), (int)component.includedPlatforms);
            }

            var enumList = Enum.GetNames(typeof(RuntimePlatform));
            var flags    = GetFlagList(enumList, component.platformsToIgnore);

            flags = EditorGUILayout.MaskField(m_GUIIncludePlatforms, flags, enumList, EditorStyles.popup);
            var newList = GetListOfIgnoredPlatforms(enumList, flags);

            if (!component.dynamic)
            {
                component.platformsToIgnore = newList;
            }
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.PropertyField(m_Timeout, m_GUITimeout);
            EditorGUILayout.PropertyField(m_Ignored, m_GUIIgnore);
            EditorGUILayout.PropertyField(m_SucceedAssertions, m_GUISuccedOnAssertions);
            EditorGUILayout.PropertyField(m_ExpectException, m_GUIExpectException);

            EditorGUI.BeginDisabledGroup(!m_ExpectException.boolValue);
            EditorGUILayout.PropertyField(m_ExpectedExceptionList, m_GUIExpectExceptionList);
            EditorGUILayout.PropertyField(m_SucceedWhenExceptionIsThrown, m_GUISucceedWhenExceptionIsThrown);
            EditorGUI.EndDisabledGroup();

            if (!component.dynamic)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
		private void DrawGroup ( TestComponent parent, int indent )
		{
			++indent;
			foreach (var test in testManager.GetChildrenTestsResults (parent))
			{
				if (test.TestComponent.IsTestGroup ())
				{
					if (DrawTestGroup (test, indent))
						DrawGroup (test.TestComponent, indent);
				}
				else
				{
					if (IsNotFiltered (test))
						DrawTest (test, indent);
				}
			}
		}
 public void TestStarted(TestResult test)
 {
     m_Window.SetCurrentTest(test.TestComponent);
     m_CurrentTest = test.TestComponent;
 }
        private void RebuildTestList()
        {
            m_TestLines = null;
            if (!TestComponent.AnyTestsOnScene() &&
                !TestComponent.AnyDynamicTestForCurrentScene())
            {
                return;
            }

            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                var dynamicTestsOnScene = TestComponent.FindAllDynamicTestsOnScene();
                var dynamicTestTypes    = TestComponent.GetTypesWithHelpAttribute(SceneManager.GetActiveScene().path);

                foreach (var dynamicTestType in dynamicTestTypes)
                {
                    var existingTests = dynamicTestsOnScene.Where(component => component.dynamicTypeName == dynamicTestType.AssemblyQualifiedName);
                    if (existingTests.Any())
                    {
                        var testComponent = existingTests.Single();
                        foreach (var c in testComponent.gameObject.GetComponents <Component>())
                        {
                            var type = Type.GetType(testComponent.dynamicTypeName);
                            if (c is TestComponent || c is Transform || type.IsInstanceOfType(c))
                            {
                                continue;
                            }
                            DestroyImmediate(c);
                        }
                        dynamicTestsOnScene.Remove(existingTests.Single());
                        continue;
                    }
                    TestComponent.CreateDynamicTest(dynamicTestType);
                }

                foreach (var testComponent in dynamicTestsOnScene)
                {
                    DestroyImmediate(testComponent.gameObject);
                }
            }

            var topTestList = TestComponent.FindAllTopTestsOnScene();

            var newResultList = new List <TestResult>();

            m_TestLines = ParseTestList(topTestList, newResultList);

            var oldDynamicResults = m_ResultList.Where(result => result.dynamicTest);

            foreach (var oldResult in m_ResultList)
            {
                var result = newResultList.Find(r => r.Id == oldResult.Id);
                if (result == null)
                {
                    continue;
                }
                result.Update(oldResult);
            }
            newResultList.AddRange(oldDynamicResults.Where(r => !newResultList.Contains(r)));
            m_ResultList = newResultList;

            IntegrationTestRendererBase.RunTest  = RunTests;
            IntegrationTestGroupLine.FoldMarkers = m_FoldMarkers;
            IntegrationTestLine.Results          = m_ResultList;

            m_FilterSettings.UpdateCounters(m_ResultList.Cast <ITestResult>());

            m_FoldMarkers.RemoveAll(o => o == null);

            selectedInHierarchy = true;
            Repaint();
        }
        public override void OnInspectorGUI()
        {
            var component = (TestComponent)target;

            if (component.dynamic)
            {
                if (GUILayout.Button("Reload dynamic tests"))
                {
                    TestComponent.DestroyAllDynamicTests();
                    Selection.objects = new Object[0];
                    IntegrationTestsRunnerWindow.selectedInHierarchy = false;
                    GUIUtility.ExitGUI();
                    return;
                }
                EditorGUILayout.HelpBox("This is a test generated from code. No changes in the component will be persisted.", MessageType.Info);
            }

            if (component.IsTestGroup())
            {
                EditorGUI.BeginChangeCheck();
                var newGroupName = EditorGUILayout.TextField(m_GUITestName, component.name);
                if (EditorGUI.EndChangeCheck())
                {
                    component.name = newGroupName;
                }

                serializedObject.ApplyModifiedProperties();
                return;
            }

            serializedObject.Update();

            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);

            EditorGUI.BeginChangeCheck();
            var newName = EditorGUILayout.TextField(m_GUITestName, component.name);

            if (EditorGUI.EndChangeCheck())
            {
                component.name = newName;
            }

            if (component.platformsToIgnore == null)
            {
                component.platformsToIgnore = GetListOfIgnoredPlatforms(Enum.GetNames(typeof(TestComponent.IncludedPlatforms)), (int)component.includedPlatforms);
            }

            var enumList = Enum.GetNames(typeof(RuntimePlatform));
            var flags    = GetFlagList(enumList, component.platformsToIgnore);

            flags = EditorGUILayout.MaskField(m_GUIIncludePlatforms, flags, enumList, EditorStyles.popup);
            var newList = GetListOfIgnoredPlatforms(enumList, flags);

            if (!component.dynamic)
            {
                component.platformsToIgnore = newList;
            }
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.PropertyField(m_Timeout, m_GUITimeout);
            EditorGUILayout.PropertyField(m_Ignored, m_GUIIgnore);
            EditorGUILayout.PropertyField(m_SucceedAssertions, m_GUISuccedOnAssertions);
            EditorGUILayout.PropertyField(m_ExpectException, m_GUIExpectException);

            EditorGUI.BeginDisabledGroup(!m_ExpectException.boolValue);
            EditorGUILayout.PropertyField(m_ExpectedExceptionList, m_GUIExpectExceptionList);
            EditorGUILayout.PropertyField(m_SucceedWhenExceptionIsThrown, m_GUISucceedWhenExceptionIsThrown);
            EditorGUI.EndDisabledGroup();

            if (!component.dynamic)
            {
                serializedObject.ApplyModifiedProperties();
            }
            if (GUI.changed)
#if UNITY_5_3_OR_NEWER
            { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); }
#else
            { EditorApplication.MarkSceneDirty(); }
#endif
        }
 public void RunFinished(List<TestResult> testResults)
 {
     m_Window.SetCurrentTest(null);
     m_CurrentTest = null;
     EditorApplication.update -= OnEditorUpdate;
     EditorApplication.isPlaying = false;
     EditorUtility.ClearProgressBar();
     GuiHelper.SetConsoleErrorPause(m_ConsoleErrorOnPauseValue);
     PlayerSettings.runInBackground = m_RunInBackground;
 }
 public static TestResult GetResultForTest(TestComponent tc)
 {
     if(!s_Instance) return new TestResult(tc);
     return s_Instance.m_ResultList.FirstOrDefault(r => r.GameObject == tc.gameObject);
 }
 public override bool SetCurrentTest(TestComponent tc)
 {
     m_IsRunning = test == tc;
     return(m_IsRunning);
 }
        public void PrintHeadPanel()
        {
            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            var layoutOptions = new[] { GUILayout.Height(24), GUILayout.Width(32) };

            if (GUILayout.Button(guiRunAllTests, Styles.buttonLeft, layoutOptions) &&
                !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                RunTests(TestComponent.FindAllTestsOnScene().Cast <ITestComponent> ().ToList());
            }

            if (GUILayout.Button(guiRunSelectedTests, Styles.buttonMid, layoutOptions) &&
                !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                RunTests(Selection.gameObjects.Select(t => t.GetComponent(typeof(TestComponent))).Cast <ITestComponent> ().ToList());
            }

            if (GUILayout.Button(guiCreateNewTest, Styles.buttonRight, layoutOptions) &&
                !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                var test = TestComponent.CreateTest();

                if (Selection.gameObjects.Length == 1 &&
                    Selection.activeGameObject != null &&
                    Selection.activeGameObject.GetComponent <TestComponent> ())
                {
                    test.transform.parent = Selection.activeGameObject.transform.parent;
                }

                Selection.activeGameObject = test;
                RebuildTestList();
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(showOptions ? guiOptionsHideLabel : guiOptionsShowLabel, GUILayout.Height(24), GUILayout.Width(80)))
            {
                showOptions = !showOptions;
            }

            EditorGUILayout.EndHorizontal();

            if (showOptions)
            {
                PrintOptions();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Filter:", GUILayout.Width(35));
            filterString = EditorGUILayout.TextField(filterString);

            if (GUILayout.Button(showAdvancedFilter ? guiAdvancedFilterHide : guiAdvancedFilterShow, GUILayout.Width(80), GUILayout.Height(16)))
            {
                showAdvancedFilter = !showAdvancedFilter;
            }

            EditorGUILayout.EndHorizontal();

            if (showAdvancedFilter)
            {
                PrintAdvancedFilter();
            }
        }
        private void RebuildTestList()
        {
            testLines = null;

            if (!TestComponent.AnyTestsOnScene())
            {
                return;
            }

            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                var dynamicTestsOnScene = TestComponent.FindAllDynamicTestsOnScene();
                var dynamicTestTypes    = TestComponent.GetTypesWithHelpAttribute(EditorApplication.currentScene);

                foreach (var dynamicTestType in dynamicTestTypes)
                {
                    var existingTests = dynamicTestsOnScene.Where(component => component.dynamicTypeName == dynamicTestType.AssemblyQualifiedName);

                    if (existingTests.Any())
                    {
                        dynamicTestsOnScene.Remove(existingTests.Single());
                        continue;
                    }

                    TestComponent.CreateDynamicTest(dynamicTestType);
                }

                foreach (var testComponent in dynamicTestsOnScene)
                {
                    DestroyImmediate(testComponent.gameObject);
                }
            }

            var topTestList = TestComponent.FindAllTopTestsOnScene();

            var newResultList = new List <TestResult> ();

            testLines = ParseTestList(topTestList, newResultList);

            var oldDynamicResults = resultList.Where(result => result.dynamicTest);

            foreach (var oldResult in resultList)
            {
                var result = newResultList.Find(r => r.Id == oldResult.Id);

                if (result == null)
                {
                    continue;
                }

                result.Update(oldResult);
            }
            newResultList.AddRange(oldDynamicResults.Where(r => !newResultList.Contains(r)));
            resultList = newResultList;

            IntegrationTestRendererBase.RunTest  = RunTests;
            IntegrationTestGroupLine.FoldMarkers = foldMarkers;
            IntegrationTestLine.Results          = resultList;

            foldMarkers.RemoveAll(o => o == null);

            selectedInHierarchy = true;
            Repaint();
        }
Exemple #16
0
        private void StartNewTest()
        {
            m_TestMessages = "";
            m_Stacktrace = "";
            m_TestState = TestState.Running;

            m_StartTime = Time.time;
            currentTest = m_TestsProvider.GetNextTest() as TestComponent;

            var testResult = m_ResultList.Single(result => result.TestComponent == currentTest);

            if (currentTest != null && currentTest.IsExludedOnThisPlatform())
            {
                m_TestState = TestState.Ignored;
                Debug.Log(currentTest.gameObject.name + " is excluded on this platform");
            }

            // don't ignore test if user initiated it from the runner and it's the only test that is being run
            if (currentTest != null
                && (currentTest.IsIgnored()
                    && !(isInitializedByRunner && m_ResultList.Count == 1)))
                m_TestState = TestState.Ignored;

            LogMessage(k_StartedMessage);
            TestRunnerCallback.TestStarted(testResult);
        }
Exemple #17
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);
 }
 public override bool SetCurrentTest(TestComponent tc)
 {
     m_IsRunning = test == tc;
     return m_IsRunning;
 }
 private void SetCurrentTest(TestComponent tc)
 {
     foreach (var line in m_TestLines)
         line.SetCurrentTest(tc);
 }
		private void StartNewTest ()
		{
			this.testMessages = "";
			this.stacktrace = "";
			testState = TestState.Running;
			assertionsToCheck = null;

			startTime = Time.time;
			currentTest = testsProvider.GetNextTest () as TestComponent;

			var testResult = resultList.Single (result => result.TestComponent == currentTest);
			
			if (currentTest.ShouldSucceedOnAssertions ())
			{
				var assertionList = currentTest.gameObject.GetComponentsInChildren<AssertionComponent> ().Where (a => a.enabled);
				if(assertionList.Any())
					assertionsToCheck = assertionList.ToArray();
			}

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

			//don't ignore test if user initiated it from the runner and it's the only test that is being run
			if (currentTest.IsIgnored () && !(isInitializedByRunner && resultList.Count == 1)) testState = TestState.Ignored;

			LogMessage(startedMessage);
			TestRunnerCallback.TestStarted (testResult);
		}
 public void TestStarted(TestResult test)
 {
     m_Window.SetCurrentTest(test.TestComponent);
     m_CurrentTest = test.TestComponent;
 }
 public abstract bool SetCurrentTest(TestComponent tc);