예제 #1
0
        public void OnTestsRun(TestReport report)
        {
            this.uxTestTree.Nodes.Clear();
            var root = this.uxTestTree.Nodes.Add("Tests");

            var overallSuccess = true;
            var overallIgnored = false;

            var testCounts = EnumExtas.Values <TestResult>().ToDictionary(key => key, key => 0);

            foreach (var collection in report.Collections)
            {
                var collectionNode = root.Nodes.Add(collection.Name);
                collectionNode.Tag = collection;

                var ignored = false;
                var failed  = false;

                foreach (var test in collection.Results)
                {
                    testCounts[test.Result]++;

                    if (test.Result == TestResult.Failure)
                    {
                        overallSuccess = false;
                        failed         = true;
                    }
                    else if (test.Result == TestResult.Ignored && !failed)
                    {
                        if (overallSuccess)
                        {
                            overallIgnored = true;
                        }

                        ignored = true;
                    }

                    var image = this.GetImageIndex(test.Result);
                    var node  = new TreeNode(test.Name, image, image)
                    {
                        Tag = test
                    };

                    collectionNode.Nodes.Add(node);
                }

                var collectionImage = this.GetImageIndex(failed, ignored);
                collectionNode.ImageIndex         = collectionImage;
                collectionNode.SelectedImageIndex = collectionImage;
            }

            var rootImage = this.GetImageIndex(!overallSuccess, overallIgnored);

            root.ImageIndex         = rootImage;
            root.SelectedImageIndex = rootImage;

            var totalTestCount = testCounts.Sum(pair => pair.Value);

            this.uxTimeMessage.Text = string.Format("Test run with {0} tests took {1}s to execute.", totalTestCount, report.TimeTaken.TotalSeconds);

            this.uxSuccessCount.Text = this.CreateCountMessage(testCounts[TestResult.Success], "passed");
            this.uxFailureCount.Text = this.CreateCountMessage(testCounts[TestResult.Failure], "failed");
            this.uxIgnoredCount.Text = this.CreateCountMessage(testCounts[TestResult.Ignored], "ignored", true);
        }
예제 #2
0
        /// <summary>
        /// Called when a report is received.
        /// </summary>
        /// <param name="report">The report, containing all test information.</param>
        public void OnTestsRun(TestReport report)
        {
            Debug.LogAlways("Console unit test log. Tests took {0}s overall to execute.", report.TimeTaken.TotalSeconds);

            var testCounts = EnumExtas.Values <TestResult>().ToDictionary(key => key, key => 0);

            foreach (var collection in report.Collections)
            {
                Debug.LogAlways("        Test collection: {0}", collection.Name);

                foreach (var test in collection.Results)
                {
                    testCounts[test.Result]++;
                    var log = test.Name;

                    if (!string.IsNullOrEmpty(test.Description))
                    {
                        log += string.Format(" ({0})", test.Description);
                    }

                    Debug.LogAlways("            {0}", log);

                    switch (test.Result)
                    {
                    case TestResult.Success:
                        Debug.LogAlways("                Test successful.");
                        break;

                    case TestResult.Failure:
                        Debug.LogAlways("                Test failed: {0} ({1} thrown at line {2} of {3})", test.Exception.Message,
                                        test.Exception.GetType().Name, test.FirstFrame.GetFileLineNumber(), test.FirstFrame.GetFileName());
                        break;

                    case TestResult.Ignored:
                        Debug.LogAlways("                Test ignored.");
                        break;
                    }
                }
            }

            var failCount           = testCounts[TestResult.Failure];
            var ignoredCount        = testCounts[TestResult.Ignored];
            var collectionFailCount = report.Collections.Count(col => col.Results.Any(test => test.Result == TestResult.Failure));

            Debug.LogAlways("Test run overview:");

            if (failCount == 0)
            {
                Debug.LogAlways("        No errors found!");
            }
            else
            {
                Debug.LogAlways("        {0} total error{1} across {2} failing test collection{3}.",
                                failCount, failCount > 1 ? "s" : string.Empty,
                                collectionFailCount, collectionFailCount > 1 ? "s" : string.Empty);
            }

            if (ignoredCount == 0)
            {
                Debug.LogAlways("        No tests ignored.");
            }
            else
            {
                Debug.LogAlways("        {0} test{1} ignored.", ignoredCount, ignoredCount > 1 ? "s" : string.Empty);
            }
        }