Esempio n. 1
0
 private void RunTest()
 {
     methodNode.ResetTestState();
     PlayModeTestRunner.RunTestByDoubleClick(
         PlayModeTestRunner.SpecificTestType.Method,
         methodNode);
 }
 public void Done()
 {
     if (!done)
     {
         PlayModeTestRunner.SavePreloadingTime(Time.time - starTime);
         done = true;
     }
 }
Esempio n. 3
0
        public override bool Draw()
        {
            PreDraw();

            if (methodNode.IsHided)
            {
                return(false);
            }

            GUILayout.Space(METHOD_MARGIN);

            Rect rect = EditorGUILayout.BeginHorizontal();


            if (currentPlayingTest.Node == methodNode)
            {
                DrawCurrentTestBackground(rect);
            }
            else
            {
                DrawBackgroundIfSelected(rect);
            }

            GUILayout.Space(20);


            HandleKeyboardEvent(RunTest);

            var prevSelection = methodNode.IsSelected;

            DrawTestLine(rect,
                         () =>
            {
                selectedNode.UpdateSelectedNode(methodNode);
            },
                         () =>
            {
                methodNode.ResetTestState();
                PlayModeTestRunner.RunTestByDoubleClick(
                    PlayModeTestRunner.SpecificTestType.Method,
                    methodNode);
            },
                         () =>
            {
                selectedNode.UpdateSelectedNode(methodNode);
                drawContextMenu = true;
            },
                         NamePostfix());

            bool isDirty = prevSelection != methodNode.IsSelected;

            EditorGUILayout.EndHorizontal();

            return(isDirty);
        }
        private void RunClass()
        {
            foreach (var method in classNode.GetChildrenOfType <MethodNode>())
            {
                method.ResetTestState();
            }

            PlayModeTestRunner.RunTestByDoubleClick(
                PlayModeTestRunner.SpecificTestType.Class,
                classNode);
        }
Esempio n. 5
0
        void AdvancedSettings()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Make reference screenshot instead of comparing:");
            var oldValue = EditorGUILayout.Toggle("", PlayModeTestRunner.ForceMakeReferenceScreenshot);

            if (oldValue != PlayModeTestRunner.ForceMakeReferenceScreenshot)
            {
                PlayModeTestRunner.ForceMakeReferenceScreenshot = oldValue;
                SetSerializedTestsDirty();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (typesReordableList != null)
            {
                typesReordableList.DoLayoutList();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Update tests on every compilation: ");
            PlayModeTestRunner.UpdateTestsOnEveryCompilation =
                GUILayout.Toggle(PlayModeTestRunner.UpdateTestsOnEveryCompilation, "");

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUI.enabled = !PlayModeTestRunner.UpdateTestsOnEveryCompilation;
            if (GUILayout.Button("Force Update Tests"))
            {
                PlayModeTestRunner.ResetTestRootNode();
                PlayModeTestRunner.SaveTestsData(true);
                rootNode = null;
            }
            GUILayout.Label("Can take several minutes...");
            GUI.enabled = PlayModeTestRunner.UpdateTestsOnEveryCompilation;
            EditorGUILayout.EndHorizontal();
        }
Esempio n. 6
0
        private void CheckAssetIsDirty()
        {
#if !UNITY_2019_1_OR_NEWER
            if (IsAssetDirtyDelegate == null)
            {
                var methodInfo = typeof(EditorUtility).GetMethod("IsDirty",
                                                                 System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
                var customDelegate = Delegate.CreateDelegate(
                    typeof(IsSerializedAssetDirty), methodInfo, false);
                IsAssetDirtyDelegate = (IsSerializedAssetDirty)customDelegate;
                instanceID           = PlayModeTestRunner.SerializedTests.GetInstanceID();
            }
            isDirty = IsAssetDirtyDelegate.Invoke(instanceID);
#else
            isDirty = EditorUtility.IsDirty(instanceID);
#endif

            if (!PlayModeTestRunner.IsRunning && previousIsDirty && !isDirty)
            {
                PlayModeTestRunner.SaveTestsData(true);
            }
            previousIsDirty = isDirty;
        }
        public override bool Draw()
        {
            PreDraw();

            if (classNode.IsHided)
            {
                return(false);
            }

            GUILayout.Space(CLASS_MARGIN);

            Rect rect = EditorGUILayout.BeginHorizontal();

            if (!IsNodeOpened && currentPlayingTest.Node != null &&
                currentPlayingTest.Node.IsChildOf(classNode))
            {
                DrawCurrentTestBackground(rect);
            }
            else
            {
                DrawBackgroundIfSelected(rect);
            }


            var isOpenedOld = IsNodeOpened;
            var isOpenedNew = DrawFoldout();

            if (IsOpenFiltered.HasValue)
            {
                IsOpenFiltered = isOpenedNew;
            }
            else
            {
                classNode.SetOpened(isOpenedNew);
            }

            HandleKeyboardEvent(RunClass);

            var prevSelection = classNode.IsSelected;

            DrawTestLine(rect,
                         () => { selectedNode.UpdateSelectedNode(classNode); },
                         () =>
            {
                foreach (var method in classNode.GetChildrenOfType <MethodNode>())
                {
                    method.ResetTestState();
                }

                PlayModeTestRunner.RunTestByDoubleClick(
                    PlayModeTestRunner.SpecificTestType.Class,
                    classNode);
            },
                         () =>
            {
                selectedNode.UpdateSelectedNode(classNode);
                drawContextMenu = true;
            },
                         string.Empty);

            var isDirty = IsNodeOpened != isOpenedOld;

            isDirty |= prevSelection != classNode.IsSelected;


            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (IsNodeOpened)
            {
                GUILayout.Space(PARENT_MARGIN);
                EditorGUILayout.BeginVertical(offsetStyle);

                foreach (var childNode in classNode.Children)
                {
                    isDirty |= childNode.View.Draw();
                }


                EditorGUILayout.EndVertical();
            }
            return(isDirty);
        }
Esempio n. 8
0
        private void DrawHeader(int width)
        {
            GUI.enabled = !Application.isPlaying && rootNode != null;

            const int buttonOffset = 3;

            width -= 10;

            GUILayout.Space(5f);

            EditorGUILayout.BeginHorizontal();

            int buttonSize = width / 4 - buttonOffset;

            if (GUILayout.Button("Select all", GUILayout.Width(buttonSize)))
            {
                if (rootNode != null)
                {
                    rootNode.SetSelected(true);
                }
            }

            if (GUILayout.Button("Deselect all", GUILayout.Width(buttonSize)))
            {
                if (rootNode != null)
                {
                    if (rootNode.IsSemiSelected)
                    {
                        rootNode.SetSelected(true);
                    }

                    rootNode.SetSelected(false);
                }
            }

            if (GUILayout.Button("Run all", GUILayout.Width(buttonSize)))
            {
                if (rootNode != null)
                {
                    foreach (var method in AllMethodNodes)
                    {
                        method.ResetTestState();
                    }

                    RunTestsMode.SelectAllTests();
                    PlayModeTestRunner.Run();
                }
            }

            if (GUILayout.Button("Run smoke", GUILayout.Width(buttonSize)))
            {
                if (rootNode != null)
                {
                    ClearAllSmokeMethods();
                    RunTestsMode.SelectOnlySmokeTests();
                    PlayModeTestRunner.Run();
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();


            if (GUILayout.Button("Run selected", GUILayout.Width(width * 0.25f - buttonOffset)))
            {
                if (rootNode != null)
                {
                    var children = rootNode.GetChildrenOfType <MethodNode>(true, false,
                                                                           node => node.IsSelected);

                    foreach (var testInfo in children)
                    {
                        testInfo.ResetTestState();
                    }

                    RunTestsMode.SelectOnlySelectedTests();
                    PlayModeTestRunner.Run();
                }
            }

            if (runTestsGivenAmountOfTimes == -1)
            {
                runTestsGivenAmountOfTimes = PlayModeTestRunner.RunTestsGivenAmountOfTimes;
            }


            GUI.enabled = true;
            GUI.SetNextControlName("Repeating");

            int newTimes = EditorGUILayout.IntSlider("Repeat Tests N Times:",
                                                     runTestsGivenAmountOfTimes, 1, 50);

            if (newTimes != runTestsGivenAmountOfTimes)
            {
                runTestsGivenAmountOfTimes = newTimes;

                PlayModeTestRunner.RunTestsGivenAmountOfTimes = newTimes;
            }

            EditorGUILayout.EndHorizontal();

            if (currentTimescale == -1)
            {
                currentTimescale = (int)PlayModeTestRunner.DefaultTimescale;
            }

            GUI.SetNextControlName("Timescale");

            int newTimescale = EditorGUILayout.IntSlider("Default Timescale:", currentTimescale, 1, 20);

            if (newTimescale != currentTimescale)
            {
                currentTimescale = newTimescale;
                PlayModeTestRunner.DefaultTimescale = currentTimescale;
            }

            GUI.enabled = !Application.isPlaying;

            var oldValue = ShowAdvancedOptions;

            ShowAdvancedOptions = EditorGUILayout.Foldout(ShowAdvancedOptions, "Advanced Options", true);
            if (ShowAdvancedOptions)
            {
                GUILayout.BeginVertical(EditorStyles.helpBox);
                AdvancedSettings();
                GUILayout.EndVertical();
            }

            if (oldValue != ShowAdvancedOptions)
            {
                editorUpdateEnabledForFrames = 10;
            }

            EditorGUILayout.LabelField("Playmode tests: ", EditorStyles.boldLabel);
            GUI.enabled = true;
        }