private static void AssignStatusAndMessage(XElement tc, ExtentTest test) { var status = StatusExtensions.ToStatus(tc.Attribute("result").Value); // error and other status messages var statusMessage = tc.Element("failure") != null?tc.Element("failure").Element("message").Value.Trim() : string.Empty; statusMessage += tc.Element("failure") != null && tc.Element("failure").Element("stack-trace") != null?tc.Element("failure").Element("stack-trace").Value.Trim() : string.Empty; statusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null?tc.Element("reason").Element("message").Value.Trim() : string.Empty; statusMessage += tc.Element("output") != null?tc.Element("output").Value.Trim() : string.Empty; statusMessage = (status == Status.Fail || status == Status.Error) ? MarkupHelper.CreateCodeBlock(statusMessage).GetMarkup() : statusMessage; statusMessage = string.IsNullOrEmpty(statusMessage) ? status.ToString() : statusMessage; test.Log(status, statusMessage); }
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 : ""; var timespan = Convert.ToDateTime(test.StartTime) - Convert.ToDateTime(test.EndTime); test.Duration = timespan.Milliseconds; // error and other status messages test.StatusMessage = tc.Element(xns + "Output") != null ? tc.Element(xns + "Output").Value.Trim() : ""; var unitTestElement = doc.Descendants(xns + "UnitTest").FirstOrDefault(x => x.Attribute("name").Value.Equals(test.Name)); if (unitTestElement != null) { var descriptionElement = unitTestElement.Element(xns + "Description"); if (descriptionElement != null) { test.Description = descriptionElement.Value; } var categories = (from testCategory in unitTestElement.Descendants(xns + "TestCategoryItem") select testCategory.Attributes("TestCategory").Select(x => x.Value).FirstOrDefault()).ToList(); test.CategoryList = categories; if (categories.Any()) { foreach (var suiteName in categories) { AddTestToSuite(report, test, suiteName); } } else { var suiteName = unitTestElement.Element(xns + "TestMethod").Attribute("className").Value; AddTestToSuite(report, test, suiteName); } } }); report.TestSuiteList = report.TestSuiteList.OrderBy(x => x.Name).ToList(); return(report); }
public Report Parse(string resultsFile) { _resultsFile = resultsFile; var doc = XDocument.Load(resultsFile); if (doc.Root == null) { throw new NullReferenceException(); } var report = new Report { FileName = Path.GetFileNameWithoutExtension(resultsFile), AssemblyName = doc.Root.Attribute("name") != null?doc.Root.Attribute("name").Value : null, TestRunner = TestRunner.NUnit }; // run-info & environment values -> RunInfo var runInfo = CreateRunInfo(doc, report); if (runInfo != null) { 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 : ""; // report status messages var testSuiteTypeAssembly = doc.Descendants("test-suite") .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly")); report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0 ? testSuiteTypeAssembly.First().Value : ""; var 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 and/or stack-trace var failure = ts.Element("failure"); if (failure != null) { var message = failure.Element("message"); if (message != null) { testSuite.StatusMessage = message.Value; } var stackTrace = failure.Element("stack-trace"); if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value)) { testSuite.StatusMessage = string.Format( "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.Value); } } var output = ts.Element("output") != null?ts.Element("output").Value:null; if (!string.IsNullOrWhiteSpace(output)) { testSuite.StatusMessage += "\n\nOutput:\n" + output; } // get test suite level categories var suiteCategories = this.GetCategories(ts, false); // 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 : ""; // get test case level categories var categories = this.GetCategories(tc, true); // if this is a parameterized test, get the categories from the parent test-suite var parameterizedTestElement = tc .Ancestors("test-suite").ToList() .Where(x => x.Attribute("type").Value.Equals("ParameterizedTest", StringComparison.CurrentCultureIgnoreCase)) .FirstOrDefault(); if (null != parameterizedTestElement) { var paramCategories = this.GetCategories(parameterizedTestElement, false); categories.UnionWith(paramCategories); } //Merge test level categories with suite level categories and add to test and report categories.UnionWith(suiteCategories); test.CategoryList.AddRange(categories); report.CategoryList.AddRange(categories); // error and other status messages test.StatusMessage = tc.Element("failure") != null && tc.Element("failure").Element("message") != null ? tc.Element("failure").Element("message").Value.Trim() : ""; test.StatusMessage += tc.Element("failure") != null ? tc.Element("failure").Element("stack-trace") != null ? tc.Element("failure").Element("stack-trace").Value.Trim() : "" : ""; test.StatusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null ? tc.Element("reason").Element("message").Value.Trim() : ""; // add NUnit console output to the status message test.StatusMessage += tc.Element("output") != null ? tc.Element("output").Value.Trim() : ""; testSuite.TestList.Add(test); }); testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList); report.TestSuiteList.Add(testSuite); }); //Sort category list so it's in alphabetical order report.CategoryList.Sort(); return(report); }
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") != null?doc.Root.Attribute("name").Value : null; report.TestRunner = TestRunner.NUnit; // run-info & environment values -> RunInfo var runInfo = CreateRunInfo(doc, report); if (runInfo != null) { 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 : ""; // report status messages var testSuiteTypeAssembly = doc.Descendants("test-suite") .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly")); report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0 ? testSuiteTypeAssembly.First().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 and/or stack-trace var failure = ts.Element("failure"); if (failure != null) { var message = failure.Element("message"); if (message != null) { testSuite.StatusMessage = message.Value; } var stackTrace = failure.Element("stack-trace"); if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value)) { testSuite.StatusMessage = string.Format( "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.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.Trim() : ""; test.StatusMessage += tc.Element("failure") != null ? tc.Element("failure").Element("stack-trace") != null ? tc.Element("failure").Element("stack-trace").Value.Trim() : "" : ""; test.StatusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null ? tc.Element("reason").Element("message").Value.Trim() : ""; // add NUnit console output to the status message test.StatusMessage += tc.Element("output") != null ? tc.Element("output").Value.Trim() : ""; testSuite.TestList.Add(test); }); testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList); report.TestSuiteList.Add(testSuite); }); return(report); }
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); }
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); }
public Report Parse(string resultsFile) { _resultsFile = resultsFile; XDocument doc = XDocument.Load(resultsFile); if (doc.Root == null) { throw new NullReferenceException(); } XAttribute assembly = doc.Root.Attribute("name"); Report report = new Report { FileName = Path.GetFileNameWithoutExtension(resultsFile), AssemblyName = assembly != null ? assembly.Value : "", TestRunner = TestRunner.XUnitV2 }; // run-info & environment values -> RunInfo RunInfo runInfo = CreateRunInfo(doc, report); if (runInfo != null) { report.AddRunInfo(runInfo.Info); } // report status messages IEnumerable <XElement> suites = doc.Descendants("collection"); suites.AsParallel().ToList().ForEach(ts => { TestSuite testSuite = new TestSuite(); string suiteName = ts.Attribute("name").Value; testSuite.Name = suiteName != null ? suiteName : ""; // Suite Time Info string suiteTime = ts.Attribute("time").Value; testSuite.Duration = suiteTime != null ? double.Parse(suiteTime) : 0; // Test Cases ts.Descendants("test").AsParallel().ToList().ForEach(tc => { Test test = new Test(); string testName = tc.Attribute("name").Value; test.Name = testName != null ? testName : ""; string result = tc.Attribute("result").Value; test.Status = result != null ? StatusExtensions.ToStatus(result) : Status.Unknown; // main a master list of all status // used to build the status filter in the view report.StatusList.Add(test.Status); // TestCase Time Info string time = tc.Attribute("time").Value; test.Duration = time != null ? double.Parse(time) : 0; // get test case level categories HashSet <string> categories = GetCategories(tc, true); if (categories.Count > 0) { test.CategoryList = categories.ToList <string>(); } // error and other status messages XElement failure = tc.Element("failure"); if (failure != null) { //string exceptionType = failure.Attribute("exception-type").Value; //test.StatusMessage = exceptionType != null ? string.Concat(exceptionType, Environment.NewLine) : ""; string message = failure.Element("message").Value; test.StatusMessage = message != null ? message : ""; string stackTrace = failure.Element("stack-trace").Value; test.StackTrace = stackTrace != null ? stackTrace : ""; } //reason for skipping a test XElement reason = tc.Element("reason"); if (reason != null) { test.StatusMessage = reason.Value; } testSuite.TestList.Add(test); }); testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList); report.TestSuiteList.Add(testSuite); }); //Sort category list so it's in alphabetical order report.CategoryList.Sort(); return(report); }
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") != null?doc.Root.Attribute("name").Value : null; report.TestRunner = TestRunner.NUnit; // run-info & environment values -> RunInfo var runInfo = CreateRunInfo(doc, report); if (runInfo != null) { 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 : ""; // report status messages var testSuiteTypeAssembly = doc.Descendants("test-suite") .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly")); report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0 ? testSuiteTypeAssembly.First().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 and/or stack-trace var failure = ts.Element("failure"); if (failure != null) { var message = failure.Element("message"); if (message != null) { testSuite.StatusMessage = message.Value; } var stackTrace = failure.Element("stack-trace"); if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value)) { testSuite.StatusMessage = string.Format( "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.Value); } } // get test suite level categories var suiteCategories = this.GetCategories(ts); // Test Cases ts.Descendants("test-case").AsParallel().ToList().ForEach(tc => { var test = new Model.Test(); test.MethodName = tc.Attribute("methodname").Value; 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 : ""; //duration string duration = tc.Attribute("duration") != null ? tc.Attribute("duration").Value : ""; if (!string.IsNullOrEmpty(duration)) { TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(duration)); test.Duration = t.ToString(@"hh\:mm\:ss\:fff"); } // 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 : ""; // get test case level categories var categories = this.GetCategories(tc); // if this is a parameterized test, get the categories from the parent test-suite var parameterizedTestElement = tc .Ancestors("test-suite").ToList() .Where(x => x.Attribute("type").Value.Equals("ParameterizedTest", StringComparison.CurrentCultureIgnoreCase)) .FirstOrDefault(); if (null != parameterizedTestElement) { var paramCategories = this.GetCategories(parameterizedTestElement); categories.UnionWith(paramCategories); } //Merge test level categories with suite level categories and add to test and report categories.UnionWith(suiteCategories); test.CategoryList.AddRange(categories); report.CategoryList.AddRange(categories); string delimeter = Environment.NewLine + "====================================================" + Environment.NewLine; // error and other status messages test.StatusMessage = tc.Element("failure") != null ? delimeter + "EXCEPTION MESSAGE: " + Environment.NewLine + tc.Element("failure").Element("message").Value.Trim() : ""; test.StatusMessage += tc.Element("failure") != null ? tc.Element("failure").Element("stack-trace") != null ? delimeter + "EXCEPTION STACKTRACE:" + Environment.NewLine + tc.Element("failure").Element("stack-trace").Value.Trim() : "" : ""; test.StatusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null ? tc.Element("reason").Element("message").Value.Trim() : ""; // add NUnit console output to the status message test.StatusMessage += tc.Element("output") != null ? delimeter + "EXECUTE STEPS:" + Environment.NewLine + tc.Element("output").Value.Trim() + delimeter : ""; //add screenshot links if (tc.Element("output") != null) { MatchCollection matches = Regex.Matches(tc.Element("output").Value.Trim(), @"Generated Screenshot:\s(<a.*a>)"); foreach (Match match in matches) { if (match.Success) { test.ScreenshotLinks.Add(match.Groups[1].Value); } } } testSuite.TestList.Add(test); }); testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList); report.TestSuiteList.Add(testSuite); }); report.TestSuiteList = report.TestSuiteList.OrderBy(ts => ts.Name).ToList(); //Sort category list so it's in alphabetical order report.CategoryList.Sort(); return(report); }
public Report Parse(string resultsFile) { this.resultsFile = resultsFile; XDocument doc = XDocument.Load(resultsFile); Report report = new Report(); report.FileName = Path.GetFileNameWithoutExtension(resultsFile); report.RunInfo.AssemblyName = doc.Root.Attribute("name") != null?doc.Root.Attribute("name").Value : null; report.RunInfo.TestRunner = TestRunner.NUnit; // run-info & environment values -> RunInfo var runInfo = CreateRunInfo(doc); if (runInfo != null) { report.RunInfo.AddInfo(runInfo); } // 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 start time report.StartTime = doc.Root.Attribute(NunitAttributeName.START_TIME) != null ? doc.Root.Attribute(NunitAttributeName.START_TIME).Value.ToDateTime() : (doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value).ToDateTime(); //report end time report.EndTime = doc.Root.Attribute(NunitAttributeName.END_TIME) != null ? doc.Root.Attribute(NunitAttributeName.END_TIME).Value.ToDateTime() : default(DateTime); //report total duration report.Duration = doc.Root.Attribute(NunitAttributeName.DURATION) == null ? 0 : doc.Root.Attribute(NunitAttributeName.DURATION).Value.ToDouble(); // report status messages var testSuiteTypeAssembly = doc.Descendants("test-suite") .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly")); report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0 ? testSuiteTypeAssembly.First().Value : ""; IEnumerable <XElement> suites = doc .Descendants("test-suite") .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase)); suites.AsParallel().ToList().ForEach(testSuiteElement => { TestSuite testSuite = GetAttributesForSuite(testSuiteElement); testSuite.TestCasesLink = GetTestCaseLink(testSuiteElement); // any error messages and/or stack-trace var failure = testSuiteElement.Element("failure"); if (failure != null) { var message = failure.Element("message"); if (message != null) { testSuite.StatusMessage = message.Value; } var stackTrace = failure.Element("stack-trace"); if (stackTrace != null && !string.IsNullOrWhiteSpace(stackTrace.Value)) { testSuite.StatusMessage = string.Format( "{0}\n\nStack trace:\n{1}", testSuite.StatusMessage, stackTrace.Value); } } var output = testSuiteElement.Element("output")?.Value; if (!string.IsNullOrWhiteSpace(output)) { testSuite.StatusMessage += $"\n\nOutput:\n" + output; } // get test suite level categories var suiteCategories = this.GetCategories(testSuiteElement, false); // Test Cases testSuiteElement.Descendants("test-case").AsParallel().ToList().ForEach(testCaseElement => { var test = new Test(); test.Name = testCaseElement.Attribute("name").Value; test.Status = StatusExtensions.ToStatus(testCaseElement.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 = testCaseElement.Attribute(NunitAttributeName.START_TIME) != null ? testCaseElement.Attribute(NunitAttributeName.START_TIME).Value.ToDateTime() : default(DateTime); test.StartTime = test.StartTime.Equals(default(DateTime)) && (testCaseElement.Attribute("time") != null) ? testCaseElement.Attribute("time").Value.ToDateTime() : test.StartTime; test.EndTime = testCaseElement.Attribute(NunitAttributeName.END_TIME) != null ? testCaseElement.Attribute(NunitAttributeName.END_TIME).Value.ToDateTime() : default(DateTime); test.Duration = testCaseElement.Attribute(NunitAttributeName.DURATION) == null ? 0 : testCaseElement.Attribute(NunitAttributeName.DURATION).Value.ToDouble(); // description var description = testCaseElement.Descendants("property") .FirstOrDefault(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase)); test.Description = description == null ? String.Empty : description.Attribute("value").Value; // link on image with error var errorImageLink = testCaseElement.Descendants("property") .FirstOrDefault(c => c.Attribute("name").Value.Equals("LinkOnImageWithError", StringComparison.CurrentCultureIgnoreCase)); test.ImageExceptionLink = errorImageLink == null ? String.Empty : errorImageLink.Attribute("value").Value; // get test case level categories var categories = this.GetCategories(testCaseElement, true); // if this is a parameterized test, get the categories from the parent test-suite var parameterizedTestElement = testCaseElement .Ancestors("test-suite").ToList() .Where(x => x.Attribute("type").Value.Equals("ParameterizedTest", StringComparison.CurrentCultureIgnoreCase)) .FirstOrDefault(); if (null != parameterizedTestElement) { var paramCategories = this.GetCategories(parameterizedTestElement, false); categories.UnionWith(paramCategories); } //Merge test level categories with suite level categories and add to test and report categories.UnionWith(suiteCategories); test.CategoryList.AddRange(categories); report.CategoryList.AddRange(categories); // error and other status messages test.StatusMessage = testCaseElement.Element("failure") != null ? testCaseElement.Element("failure").Element("message").Value.Trim() : ""; test.StatusMessage += testCaseElement.Element("failure") != null ? testCaseElement.Element("failure").Element("stack-trace") != null ? testCaseElement.Element("failure").Element("stack-trace").Value.Trim() : "" : ""; test.StatusMessage += testCaseElement.Element("reason") != null && testCaseElement.Element("reason").Element("message") != null ? testCaseElement.Element("reason").Element("message").Value.Trim() : ""; // add NUnit console output to the status message test.StatusMessage += testCaseElement.Element("output") != null ? testCaseElement.Element("output").Value.Trim() : ""; testSuite.TestList.Add(test); }); testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList); report.TestSuiteList.Add(testSuite); }); //Sort category list so it's in alphabetical order report.CategoryList.Sort(); return(report); }