public Report Parse(string resultsFile)
        {
            var doc = XDocument.Load(resultsFile);

            var report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Descendants(xns + "files").First().Descendants(xns + "file").First().Value;
            report.TestParser = this;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // test cases
            var tests = doc.Descendants(xns + "testStep")
                .Where(x => x.Attribute("isTestCase").Value.Equals("true", StringComparison.CurrentCultureIgnoreCase));

            // report counts
            var statistics = doc.Descendants(xns + "statistics").First();
            report.Total = tests.Count();
            report.Passed = Int32.Parse(statistics.Attribute("passedCount").Value);
            report.Failed = Int32.Parse(statistics.Attribute("failedCount").Value);
            report.Inconclusive = Int32.Parse(statistics.Attribute("inconclusiveCount").Value);
            report.Skipped = Int32.Parse(statistics.Attribute("skippedCount").Value);
            report.Errors = 0;

            // report duration
            XElement testPackageRun = doc.Descendants(xns + "testPackageRun").First();
            report.StartTime = testPackageRun.Attribute("startTime").Value;
            report.EndTime = testPackageRun.Attribute("endTime").Value;

            var suitesList = new List<string>();
            TestSuite testSuite = null;

            tests.AsParallel().ToList().ForEach(tc =>
            {
                var testSuiteName = tc.Attribute("fullName").Value;
                testSuiteName = testSuiteName.Contains('/')
                    ? testSuiteName.Split('/')[testSuiteName.Split('/').Length - 2]
                    : testSuiteName;

                if (!suitesList.Contains(testSuiteName))
                {
                    testSuite = new TestSuite();
                    testSuite.Name = testSuiteName;
                    testSuite.StartTime = tc.Parent.Attribute("startTime").Value;
                    testSuite.EndTime = tc.Parent.Attribute("endTime").Value;

                    report.TestSuiteList.Add(testSuite);

                    suitesList.Add(testSuiteName);
                }

                var test = new Model.Test();

                test.Name = tc.Attribute("name").Value;
                test.Status = StatusExtensions.ToStatus(tc.Parent.Descendants(xns + "outcome").First().Attribute("status").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.AddStatus(test.Status);

                var entry = tc.Descendants(xns + "entry");

                // description
                var description = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Description"))
                    : null;
                test.Description =  description != null && description.Count() > 0
                    ? description.First().Value
                    : "";

                // error and other status messages
                var ignoreReason = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("IgnoreReason"))
                    : null;
                test.StatusMessage = ignoreReason != null && ignoreReason.Count() > 0
                    ? ignoreReason.First().Value
                    : "";

                var testLog = tc.Parent.Descendants(xns + "testLog");
                test.StatusMessage += testLog != null && testLog.Count() > 0
                    ? testLog.First().Value
                    : "";

                // assign categories
                var category = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Category"))
                    : null;
                if (category != null && category.Count() > 0)
                {
                    category.ToList().ForEach(s =>
                    {
                        string cat = s.Value;

                        test.CategoryList.Add(cat);
                        report.AddCategory(cat);
                    });
                }

                testSuite.TestList.Add(test);
                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
            });

            return report;
        }
Example #2
0
        public Report Parse(string resultsFile)
        {
            this.resultsFile = resultsFile;

            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Root.Attribute("name").Value;
            report.TestRunner = TestRunner.NUnit;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report);
            report.AddRunInfo(runInfo.Info);

            // report counts
            report.Total = doc.Descendants("test-case").Count();

            report.Passed =
                doc.Root.Attribute("passed") != null
                    ? Int32.Parse(doc.Root.Attribute("passed").Value)
                    : doc.Descendants("test-case").Where(x => x.Attribute("result").Value.Equals("success", StringComparison.CurrentCultureIgnoreCase)).Count();

            report.Failed =
                doc.Root.Attribute("failed") != null
                    ? Int32.Parse(doc.Root.Attribute("failed").Value)
                    : Int32.Parse(doc.Root.Attribute("failures").Value);

            report.Errors =
                doc.Root.Attribute("errors") != null
                    ? Int32.Parse(doc.Root.Attribute("errors").Value)
                    : 0;

            report.Inconclusive =
                doc.Root.Attribute("inconclusive") != null
                    ? Int32.Parse(doc.Root.Attribute("inconclusive").Value)
                    : Int32.Parse(doc.Root.Attribute("inconclusive").Value);

            report.Skipped =
                doc.Root.Attribute("skipped") != null
                    ? Int32.Parse(doc.Root.Attribute("skipped").Value)
                    : Int32.Parse(doc.Root.Attribute("skipped").Value);

            report.Skipped +=
                doc.Root.Attribute("ignored") != null
                    ? Int32.Parse(doc.Root.Attribute("ignored").Value)
                    : 0;

            // report duration
            report.StartTime =
                doc.Root.Attribute("start-time") != null
                    ? doc.Root.Attribute("start-time").Value
                    : doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value;

            report.EndTime =
                doc.Root.Attribute("end-time") != null
                    ? doc.Root.Attribute("end-time").Value
                    : "";

            IEnumerable<XElement> suites = doc
                .Descendants("test-suite")
                .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase));

            suites.AsParallel().ToList().ForEach(ts =>
            {
                var testSuite = new TestSuite();
                testSuite.Name = ts.Attribute("name").Value;

                // Suite Time Info
                testSuite.StartTime =
                    ts.Attribute("start-time") != null
                        ? ts.Attribute("start-time").Value
                        : string.Empty;

                testSuite.StartTime =
                    String.IsNullOrEmpty(testSuite.StartTime) && ts.Attribute("time") != null
                        ? ts.Attribute("time").Value
                        : testSuite.StartTime;

                testSuite.EndTime =
                    ts.Attribute("end-time") != null
                        ? ts.Attribute("end-time").Value
                        : "";

                // any error messages or stack-trace
                testSuite.StatusMessage =
                    ts.Element("failure") != null
                        ? ts.Element("failure").Element("message").Value
                        : "";

                // Test Cases
                ts.Descendants("test-case").AsParallel().ToList().ForEach(tc =>
                {
                    var test = new Model.Test();

                    test.Name = tc.Attribute("name").Value;
                    test.Status = StatusExtensions.ToStatus(tc.Attribute("result").Value);

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    // TestCase Time Info
                    test.StartTime =
                        tc.Attribute("start-time") != null
                            ? tc.Attribute("start-time").Value
                            : "";
                    test.StartTime =
                        String.IsNullOrEmpty(test.StartTime) && (tc.Attribute("time") != null)
                            ? tc.Attribute("time").Value
                            : test.StartTime;
                    test.EndTime =
                        tc.Attribute("end-time") != null
                            ? tc.Attribute("end-time").Value
                            : "";

                    // description
                    var description =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase));
                    test.Description =
                        description.Count() > 0
                            ? description.ToArray()[0].Attribute("value").Value
                            : "";

                    bool hasCategories =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase)).Count() > 0;

                    if (hasCategories)
                    {
                        List<XElement> cats = tc
                            .Descendants("property")
                            .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase))
                            .ToList();

                        cats.ForEach(x =>
                        {
                            string cat = x.Attribute("value").Value;

                            test.CategoryList.Add(cat);
                            report.CategoryList.Add(cat);
                        });
                    }

                    // error and other status messages
                    test.StatusMessage =
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("message").Value
                            : "";
                    test.StatusMessage +=
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("stack-trace") != null
                                ? tc.Element("failure").Element("stack-trace").Value
                                : ""
                            : "";

                    testSuite.TestList.Add(test);
                });

                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);

                report.TestSuiteList.Add(testSuite);
            });

            return report;
        }
Example #3
0
        public Report Parse(string resultsFile)
        {
            ResultsFile = resultsFile;

            var doc = XDocument.Load(resultsFile);

            var report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Descendants(_xns + "files").First().Descendants(_xns + "file").First().Value;
            report.TestRunner = TestRunner.Gallio;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // test cases
            var tests = doc.Descendants(_xns + "testStep")
                .Where(x => x.Attribute("isTestCase").Value.Equals("true", StringComparison.CurrentCultureIgnoreCase));

            // report counts
            var statistics = doc.Descendants(_xns + "statistics").First();
            var xElements = tests as XElement[] ?? tests.ToArray();
            report.Total = xElements.Count();
            report.Passed = int.Parse(statistics.Attribute("passedCount").Value);
            report.Failed = int.Parse(statistics.Attribute("failedCount").Value);
            report.Inconclusive = int.Parse(statistics.Attribute("inconclusiveCount").Value);
            report.Skipped = int.Parse(statistics.Attribute("skippedCount").Value);
            report.Errors = 0;

            // report duration
            var testPackageRun = doc.Descendants(_xns + "testPackageRun").First();
            report.StartTime = testPackageRun.Attribute("startTime").Value;
            report.EndTime = testPackageRun.Attribute("endTime").Value;

            var suitesList = new List<string>();
            TestSuite testSuite = null;

            xElements.AsParallel().ToList().ForEach(tc =>
            {
                var testSuiteName = tc.Attribute("fullName").Value;
                testSuiteName = testSuiteName.Contains('/')
                    ? testSuiteName.Split('/')[testSuiteName.Split('/').Length - 2]
                    : testSuiteName;

                if (!suitesList.Contains(testSuiteName))
                {
                    if (tc.Parent != null)
                        testSuite = new TestSuite
                        {
                            Name = testSuiteName,
                            StartTime = tc.Parent.Attribute("startTime").Value,
                            EndTime = tc.Parent.Attribute("endTime").Value
                        };

                    report.TestSuiteList.Add(testSuite);

                    suitesList.Add(testSuiteName);
                }

                var test = new Test
                {
                    Name = tc.Attribute("name").Value
                };

                if (tc.Parent != null)
                {
                    test.Status = tc.Parent.Descendants(_xns + "outcome").First().Attribute("status").Value.ToStatus();

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    var entry = tc.Descendants(_xns + "entry");

                    // description
                    var enumerable = entry as XElement[] ?? entry.ToArray();
                    var description = enumerable.Where(x => x.Attribute("key").Value.Equals("Description"));
                    var elements = description as XElement[] ?? description.ToArray();
                    test.Description = elements.Any()
                        ? elements.First().Value
                        : "";

                    // error and other status messages
                    var ignoreReason = enumerable.Where(x => x.Attribute("key").Value.Equals("IgnoreReason"));
                    var reason = ignoreReason as XElement[] ?? ignoreReason.ToArray();
                    test.StatusMessage = reason.Any()
                        ? reason.First().Value
                        : "";

                    if (tc.Parent != null)
                    {
                        var testLog = tc.Parent.Descendants(_xns + "testLog");
                        var log = testLog as XElement[] ?? testLog.ToArray();
                        test.StatusMessage += log.Any()
                            ? log.First().Value
                            : "";
                    }

                    // assign categories
                    var category = enumerable.Where(x => x.Attribute("key").Value.Equals("Category"));
                    var xElements1 = category as XElement[] ?? category.ToArray();
                    if (xElements1.Any())
                    {
                        xElements1.ToList().ForEach(s =>
                        {
                            var cat = s.Value;

                            test.CategoryList.Add(cat);
                            report.CategoryList.Add(cat);
                        });
                    }
                }

                if (testSuite == null) return;
                testSuite.TestList.Add(test);
                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
            });

            return report;
        }
Example #4
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");
            report.Total = resultNodes.Count();
            report.Passed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                .Where(x => 
                    x.Attribute("outcome").Value.Equals("Inconclusive") 
                    || x.Attribute("outcome").Value.Equals("passedButRunAborted") 
                    || x.Attribute("outcome").Value.Equals("disconnected") 
                    || x.Attribute("outcome").Value.Equals("notRunnable") 
                    || x.Attribute("outcome").Value.Equals("warning") 
                    || x.Attribute("outcome").Value.Equals("pending"))
                .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors = resultNodes
                .Where(x => 
                    x.Attribute("outcome").Value.Equals("Passed") 
                    || x.Attribute("outcome").Value.Equals("Aborted") 
                    || x.Attribute("outcome").Value.Equals("timeout"))
                .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();
            report.StartTime = times.Attribute("start").Value;
            report.EndTime = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";
                test.Duration = TimeSpan.Parse(tc.Attribute("duration").Value).TotalMilliseconds;

                // error and other status messages
                test.StatusMessage =
                    tc.Element(xns + "Output") != null
                        ? tc.Element(xns + "Output").Value.Trim()
                        : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").Where(x => x.Attribute("name").Value.Equals(test.Name));
                if (unitTestElement != null && unitTestElement.Count() > 0)
                {
                    var className = unitTestElement.First().Element(xns + "TestMethod").Attribute("className").Value;
                    var testSuite = report.TestSuiteList.SingleOrDefault(t => t.Name.Equals(className));

                    if (testSuite == null)
                    {
                        testSuite = new TestSuite();
                        testSuite.Name = className;

                        report.TestSuiteList.Add(testSuite);
                    }

                    testSuite.TestList.Add(test);
                    testSuite.Duration += test.Duration;
                    testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
                }
            });

            return report;
        }
Example #5
0
        private static void AddTestToSuite(Report report, Test test, string suiteName)
        {
            var testSuite = report.TestSuiteList.SingleOrDefault(t => t.Name.Equals(suiteName));

            if (testSuite == null)
            {
                testSuite = new TestSuite { Name = suiteName };
                report.TestSuiteList.Add(testSuite);
            }

            testSuite.TestList.Add(test);
            testSuite.Duration += test.Duration;
            testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
        }