public IEnumerable<TestNodeNamespace> CreateMutantTestTree(List<TmpTestNodeMethod> nodeMethods)
        {

            var list = nodeMethods.GroupBy(n => ExtractTypeName(n.Name)).ToList();

            TestsRootNode root = new TestsRootNode();
            var u = new Utilss();
            u.GroupTypes<IGrouping<string, TmpTestNodeMethod>, TestTreeNode>(
                root, n => ExtractTypeName(n.Key),
                (parent, name) => new TestNodeNamespace(parent, name),
                (parent, collection) =>
                {
                    foreach (var grouping in collection)
                    {
                        var testNodeClass = new TestNodeClass(ExtractName(grouping.Key));
                        testNodeClass.Parent = parent;
                        parent.Children.Add(testNodeClass);
                        foreach (var tmpMethod in grouping)
                        {
                            var testNodeMethod = new TestNodeMethod(testNodeClass, ExtractName(tmpMethod.Name));
                            testNodeMethod.State = tmpMethod.State;
                            testNodeMethod.Message = tmpMethod.Message;
                            testNodeClass.Children.Add(testNodeMethod);
                        }
                    }
                }, list);
            return root.Children.Cast<TestNodeNamespace>();
        }
Ejemplo n.º 2
0
        public IEnumerable <TestNodeNamespace> CreateMutantTestTree(List <TmpTestNodeMethod> nodeMethods)
        {
            var list = nodeMethods.GroupBy(n => ExtractTypeName(n.Name)).ToList();

            TestsRootNode root = new TestsRootNode();
            var           u    = new Utilss();

            u.GroupTypes <IGrouping <string, TmpTestNodeMethod>, TestTreeNode>(
                root, n => ExtractTypeName(n.Key),
                (parent, name) => new TestNodeNamespace(parent, name),
                (parent, collection) =>
            {
                foreach (var grouping in collection)
                {
                    var testNodeClass    = new TestNodeClass(ExtractName(grouping.Key));
                    testNodeClass.Parent = parent;
                    parent.Children.Add(testNodeClass);
                    foreach (var tmpMethod in grouping)
                    {
                        var testNodeMethod     = new TestNodeMethod(testNodeClass, ExtractName(tmpMethod.Name));
                        testNodeMethod.State   = tmpMethod.State;
                        testNodeMethod.Message = tmpMethod.Message;
                        testNodeClass.Children.Add(testNodeMethod);
                    }
                }
            }, list);
            return(root.Children.Cast <TestNodeNamespace>());
        }
Ejemplo n.º 3
0
        public async Task<TestsRootNode> LoadTests(IList<string> assembliesPaths)
        {
            _log.Info("Loading tests from: "+string.Join(",", assembliesPaths));
            var tasks = new Dictionary<string, Task<May<TestNodeAssembly>>>();
            var testsRootNode = new TestsRootNode();

            
            foreach (var path in assembliesPaths)
            {
                string path1 = path;
                string assemblyName = Path.GetFileNameWithoutExtension(path);
                var testNodeAssembly = new TestNodeAssembly(testsRootNode, assemblyName);
                testNodeAssembly.AssemblyPath = path;

                var task = LoadFor(path1, testNodeAssembly);
                tasks.Add(path, task);

            }
            var assemblies = await Task.WhenAll(tasks.Values);
            
            testsRootNode.Children.AddRange(assemblies.WhereHasValue());
            testsRootNode.State = TestNodeState.Inactive;
            testsRootNode.IsIncluded = true;
            return testsRootNode;
            

        }
Ejemplo n.º 4
0
        public async Task <TestsRootNode> LoadTests(IList <string> assembliesPaths)
        {
            _log.Info("Loading tests from: " + string.Join(",", assembliesPaths));
            var testsRootNode = new TestsRootNode();

            await GetTestAssemblyNodes(assembliesPaths, testsRootNode);

            return(testsRootNode);
        }
 private void SelectOnlyCoveredTests(TestsRootNode rootNode, List<MethodIdentifier> coveredTests)
 {
     rootNode.IsIncluded = false;
     var toSelect = rootNode.Children.SelectManyRecursive(n => n.Children, leafsOnly: true)
         .OfType<TestNodeMethod>()
         .Where(t => coveredTests.Contains(t.Identifier));
     foreach (var testNodeMethod in toSelect)
     {
         testNodeMethod.IsIncluded = true;
     }
 }
Ejemplo n.º 6
0
        private void SelectOnlyCoveredTests(TestsRootNode rootNode, List <MethodIdentifier> coveredTests)
        {
            rootNode.IsIncluded = false;
            var toSelect = rootNode.Children.SelectManyRecursive(n => n.Children, leafsOnly: true)
                           .OfType <TestNodeMethod>()
                           .Where(t => coveredTests.Contains(t.Identifier));

            foreach (var testNodeMethod in toSelect)
            {
                testNodeMethod.IsIncluded = true;
            }
        }
Ejemplo n.º 7
0
        private async Task LoadFor(IEnumerable <string> path1, TestsRootNode testsRootNode)
        {
            var contexts = await _testServiceManager.LoadTests(path1);

            foreach (var testContext in contexts.OrderBy(p => p.AssemblyName))
            {
                var testNodeAssembly = new TestNodeAssembly(testsRootNode, testContext.AssemblyName);

                testNodeAssembly.TestsLoadContexts = new List <TestsLoadContext> {
                    testContext
                };

                var allClassNodes = testContext.ClassNodes;

                IEnumerable <TestNodeNamespace> testNamespaces = TestsLoadContext.GroupTestClasses(allClassNodes.ToList(), testNodeAssembly);

                testNodeAssembly.Children.AddRange(testNamespaces);

                testsRootNode.Children.Add(testNodeAssembly);
            }
        }
Ejemplo n.º 8
0
        public async Task <TestsRootNode> LoadTests(IList <string> assembliesPaths)
        {
            _log.Info("Loading tests from: " + string.Join(",", assembliesPaths));
            var tasks         = new Dictionary <string, Task <May <TestNodeAssembly> > >();
            var testsRootNode = new TestsRootNode();


            foreach (var path in assembliesPaths)
            {
                string path1            = path;
                string assemblyName     = Path.GetFileNameWithoutExtension(path);
                var    testNodeAssembly = new TestNodeAssembly(testsRootNode, assemblyName);
                testNodeAssembly.AssemblyPath = path;

                var task = LoadFor(path1, testNodeAssembly);
                tasks.Add(path, task);
            }
            var assemblies = await Task.WhenAll(tasks.Values);

            testsRootNode.Children.AddRange(assemblies.WhereHasValue());
            testsRootNode.State      = TestNodeState.Inactive;
            testsRootNode.IsIncluded = true;
            return(testsRootNode);
        }
Ejemplo n.º 9
0
 private async Task GetTestAssemblyNodes(IList <string> assembliesPaths, TestsRootNode testsRootNode)
 {
     await LoadFor(assembliesPaths, testsRootNode);
 }
        private IEnumerator ProcessTestQueue()
        {
            Debug.LogFormat("[PlayModeTestRunner] ProcessTestQueueProcess: Mode {0}", RunTestsMode.Mode);

            ClassNode previousClassNode = null;

            ITestRunnerCallbackReceiver[] callbackables = TriggerBeforeTestRunEvent(Callbackables);

            List <MethodNode> methods = null;

            if (RunTestsMode.Mode == RunTestsMode.RunTestsModeEnum.DoubleClick)
            {
                if (!string.IsNullOrEmpty(RunTestsMode.NodeToRunFullName))
                {
                    var targetNodes =
                        TestsRootNode.GetChildrenOfType <Node>(true, false,
                                                               node =>
                    {
                        return(node.FullName.Equals(RunTestsMode.NodeToRunFullName, StringComparison.Ordinal));
                    });

                    if (targetNodes.Count > 0)
                    {
                        var targetNode = targetNodes[0];
                        if (targetNode is MethodNode)
                        {
                            methods = new List <MethodNode>
                            {
                                (MethodNode)targetNode
                            };
                        }
                        else
                        {
                            methods = targetNode.GetChildrenOfType <MethodNode>();
                        }
                    }
                }
            }

            if (methods == null || methods.Count == 0)
            {
                methods = TestsRootNode.GetChildrenOfType <MethodNode>();
            }

            Debug.LogFormat("[PlayModeTestRunner] NonFilteredMethods: {0}", methods.Count);

            methods = methods.Where(methodNode =>
            {
                Debug.LogFormat("method data: IsSmoke: {0}  isSelected: {1}",
                                methodNode.TestSettings.IsSmoke,
                                methodNode.IsSelected);

                if (RunTestsMode.Mode == RunTestsMode.RunTestsModeEnum.Smoke &&
                    !methodNode.TestSettings.IsSmoke)
                {
                    return(false);
                }

                if (RunTestsMode.Mode == RunTestsMode.RunTestsModeEnum.Selected &&
                    !methodNode.IsSelected)
                {
                    return(false);
                }

                if (Namespaces != null && Namespaces.Length > 0)
                {
                    var result = false;

                    for (int i = 0; i < Namespaces.Length; i++)
                    {
                        var contains = methodNode.FullName.IndexOf(Namespaces[i],
                                                                   StringComparison.OrdinalIgnoreCase) != -1;
                        result |= contains;
                    }

                    return(result);
                }

                return(true);
            }).ToList();

            Debug.LogFormat("[PlayModeTestRunner] FilteredMethods: {0}", methods.Count);

            testInfoData.Total = methods.Count;
            for (int i = 0; i < methods.Count; i++)
            {
                var methodNode = methods[i];
                TestStep.Reset();
                ClassNode classNode = (ClassNode)methodNode.Parent;

                Debug.Log("QA: Process " + classNode.Type + " testClass.TestMethods #: " + classNode.Children.Count());
                CurrentPlayingMethodNode.UpdateCurrentPlayingNode(methodNode);
                playModeLogger.Logs.Clear();
                if (methodNode.TestSettings.IsIgnored)
                {
                    ProcessIgnore(methodNode);
                    continue;
                }

                for (int repeatTime = 0; repeatTime < RunTestsGivenAmountOfTimes; repeatTime++)
                {
                    exceptionThrown = false;
#if UNITY_EDITOR
                    if (methodNode.TestSettings.EditorTargetResolution != null)
                    {
                        CustomResolution resolution = methodNode.TestSettings.EditorTargetResolution;

                        if (resolution.Width != Screen.width ||
                            resolution.Height != Screen.height)
                        {
                            GameViewResizer.SetResolution(resolution.Width, resolution.Height);
                        }
                    }
#endif

                    if (!methodNode.TestSettings.ContainsTargetResolution(Screen.width, Screen.height))
                    {
#if UNITY_EDITOR
                        if (methodNode.TestSettings.EditorTargetResolution == null)
                        {
                            Debug.LogWarning(String.Format("PlayModeTestRunner: TARGET RESOLUTION {0}:{1}",
                                                           methodNode.TestSettings.DefaultTargetResolution.Width,
                                                           methodNode.TestSettings.DefaultTargetResolution.Height));

                            GameViewResizer.SetResolution(methodNode.TestSettings.DefaultTargetResolution.Width,
                                                          methodNode.TestSettings.DefaultTargetResolution.Height);
                        }
#else
                        ProcessIgnore(methodNode);
                        continue;
#endif
                    }

                    object testInstance = null;
                    screenGUIDrawer.SetCurrentTest(methodNode.FullName);
                    playModeLogger.StartLog(methodNode.FullName);

                    try
                    {
                        testInstance = Activator.CreateInstance(classNode.Type);
                    }
                    catch (Exception ex)
                    {
                        if (classNode.Type == null)
                        {
                            Debug.LogErrorFormat("Can't instantiate class - class type is null." +
                                                 " class probably was deleted ");
                        }
                        else
                        {
                            Debug.LogErrorFormat("Can't instantiate class \"{0}\". Exception: \"{1}\"",
                                                 classNode.Type.FullName, ex.Message);
                        }

                        ProcessTestFail(methodNode);
                        continue;
                    }

                    Time.timeScale = DefaultTimescale;
                    Debug.Log("QA: Running testClass: " + classNode.Type);

                    if (classNode != previousClassNode)
                    {
                        previousClassNode = classNode;

                        yield return(RunMethods(classNode.OneTimeSetUpMethods, testInstance, true));

                        if (exceptionThrown)
                        {
                            Debug.LogError("Fail during executing set up methods.");
                            ProcessTestFail(methodNode);
                            continue;
                        }
                    }

                    yield return(RunMethods(classNode.SetUpMethods, testInstance, true));

                    if (exceptionThrown)
                    {
                        Debug.LogError("Fail during executing set up methods.");
                        ProcessTestFail(methodNode);
                        continue;
                    }

                    yield return(InvokeTestMethod(testInstance, methodNode));

                    var exceptionDuringTestMethod = exceptionThrown;
                    exceptionThrown = false;

                    yield return(RunMethods(classNode.TearDownMethods, testInstance, false));

                    if (i + 1 == methods.Count ||
                        methods[i + 1].Parent != classNode)
                    {
                        yield return(RunMethods(classNode.OneTimeTearDownMethods, testInstance, true));
                    }

                    if (!exceptionDuringTestMethod && exceptionThrown)
                    {
                        Debug.LogError("Fail during executing tear down methods.");
                        ProcessTestFail(methodNode);
                        continue;
                    }

                    if (exceptionDuringTestMethod)
                    {
                        ProcessTestFail(methodNode);
                        continue;
                    }

                    testInfoData.AddSuccess(methodNode.FullName);
                    playModeLogger.EndLog(methodNode.FullName);
                    methodNode.SetTestState(TestState.Passed);
                    methodNode.Logs = playModeLogger.LogsCopy;
                    methodNode.SetStep(TestStep.CurrentIndex);

                    if (OnMethodStateUpdated != null)
                    {
                        OnMethodStateUpdated();
                    }
                }
            }

            TriggerAfterTestRunEvent(callbackables);

            FinalizeTest();
        }