public SummaryResult ParseSummary(string rawResult) { const string kDurationStart = "(Total execution time: "; int durationStart = rawResult.IndexOf(kDurationStart) + kDurationStart.Length; int durationEnd = rawResult.IndexOf(" sec", durationStart); int totalEnd = rawResult.IndexOf(" run", durationEnd); int totalStart = rawResult.IndexOf("\n\n", durationEnd) + 2; int passedEnd = rawResult.IndexOf(" passed", durationEnd); int passedStart = rawResult.LastIndexOf(' ', passedEnd - 1) + 1; int failedEnd = rawResult.IndexOf(" failed", durationEnd); int failedStart = rawResult.LastIndexOf(' ', failedEnd - 1) + 1; int skippedEnd = rawResult.IndexOf(" skipped", durationEnd); int skippedStart = rawResult.LastIndexOf(' ', skippedEnd - 1) + 1; SummaryResult result = new SummaryResult(); result.Duration = rawResult.Substring(durationStart, durationEnd - durationStart); result.TotalCount = rawResult.Substring(totalStart, totalEnd - totalStart); result.PassCount = rawResult.Substring(passedStart, passedEnd - passedStart); result.FailCount = rawResult.Substring(failedStart, failedEnd - failedStart); result.SkipCount = rawResult.Substring(skippedStart, skippedEnd - skippedStart); return(result); }
/// <summary> /// Emit the AllTestsComplete event /// </summary> protected void RaiseAllComplete(SummaryResult result) { if (AllTestsComplete != null) { AllTestsComplete(this, new AllTestsCompleteEventArgs(result.PassCount, result.FailCount, result.SkipCount, result.Duration)); } }
/// <summary> /// Break out results and raise appropriate events /// </summary> /// <param name="resultSource"></param> private void ParseResults(System.Xml.XmlNode resultSource) { SummaryResult result = new SummaryResult(); if (resultSource == null) { result.Duration = "0"; result.TotalCount = "0"; result.PassCount = "0"; result.FailCount = "0"; result.SkipCount = "0"; } else { for (int i = 0; i < resultSource.ChildNodes.Count; i++) { ProcessTest(XunitResultXmlUtility.GetResult(resultSource, i)); } result.Duration = GetAttribute(resultSource, "time"); result.TotalCount = "0"; result.PassCount = GetAttribute(resultSource, "passed"); result.FailCount = GetAttribute(resultSource, "failed"); result.SkipCount = GetAttribute(resultSource, "skipped"); } RaiseAllComplete(result); }
public SummaryResult ParseSummary(string rawResult) { //Disposing the test runner.\nStop time: 7:22 AM (Total execution time: 22.019 seconds)\n\n6 run, 1 passed, 5 failed, 0 inconclusive, 0 skipped\n\n\n"; SummaryResult result = new SummaryResult(); string footer = rawResult.Substring(rawResult.IndexOf("\nStop time:")); result.Duration = Regex.Match(footer, @"\d+\.\d+").Value; result.TotalCount = Regex.Match(Regex.Match(footer, @"\d+\srun").Value, @"\d+").Value; result.PassCount = Regex.Match(Regex.Match(footer, @"\d+\spassed").Value, @"\d+").Value; result.FailCount = Regex.Match(Regex.Match(footer, @"\d+\sfailed").Value, @"\d+").Value; result.SkipCount = Regex.Match(Regex.Match(footer, @"\d+\sskipped").Value, @"\d+").Value; return(result); }
public static SummaryResult ParseSummary(List <string> source) { SummaryResult result = new SummaryResult(); string summaryLine = source.Find(line => line.Trim().StartsWith("<test-results name=")); if (!string.IsNullOrEmpty(summaryLine)) { //<test-results name="redgreenplayground.dll" total="5" failures="4" not-run="1" date="2009-10-02" time="10:35:46"> string[] attributes = summaryLine.Split(' '); foreach (string keyValue in attributes) { if (keyValue.Contains("=")) { int delimiter = keyValue.IndexOf("="); string key = keyValue.Substring(0, delimiter); string value = keyValue.Substring(delimiter + 2, keyValue.Length - delimiter - 3); switch (key) { case "total": result.TotalCount = value; break; case "failures": result.FailCount = value; break; case "not-run": result.SkipCount = value; break; default: break; } } } result.PassCount = (int.Parse(result.TotalCount) - int.Parse(result.FailCount)).ToString(); result.Duration = String.Empty; } return(result); }
public SummaryResult ParseSummary(string rawResult) { const string kDurationStart = "(Total execution time: "; int durationStart = rawResult.IndexOf(kDurationStart) + kDurationStart.Length; int durationEnd = rawResult.IndexOf(" sec", durationStart); int totalEnd = rawResult.IndexOf(" run", durationEnd); int totalStart = rawResult.IndexOf("\n\n", durationEnd) + 2; int passedEnd = rawResult.IndexOf(" passed", durationEnd); int passedStart = rawResult.LastIndexOf(' ', passedEnd - 1) + 1; int failedEnd = rawResult.IndexOf(" failed", durationEnd); int failedStart = rawResult.LastIndexOf(' ', failedEnd - 1) + 1; int skippedEnd = rawResult.IndexOf(" skipped", durationEnd); int skippedStart = rawResult.LastIndexOf(' ', skippedEnd - 1) + 1; SummaryResult result = new SummaryResult(); result.Duration = rawResult.Substring(durationStart, durationEnd - durationStart); result.TotalCount = rawResult.Substring(totalStart, totalEnd - totalStart); result.PassCount = rawResult.Substring(passedStart, passedEnd - passedStart); result.FailCount = rawResult.Substring(failedStart, failedEnd - failedStart); result.SkipCount = rawResult.Substring(skippedStart, skippedEnd - skippedStart); return result; }
public SummaryResult ParseSummary(string rawResult) { //Disposing the test runner.\nStop time: 7:22 AM (Total execution time: 22.019 seconds)\n\n6 run, 1 passed, 5 failed, 0 inconclusive, 0 skipped\n\n\n"; SummaryResult result = new SummaryResult(); string footer = rawResult.Substring(rawResult.IndexOf("\nStop time:")); result.Duration = Regex.Match(footer, @"\d+\.\d+").Value; result.TotalCount = Regex.Match(Regex.Match(footer, @"\d+\srun").Value, @"\d+").Value; result.PassCount = Regex.Match(Regex.Match(footer, @"\d+\spassed").Value, @"\d+").Value; result.FailCount = Regex.Match(Regex.Match(footer, @"\d+\sfailed").Value, @"\d+").Value; result.SkipCount = Regex.Match(Regex.Match(footer, @"\d+\sskipped").Value, @"\d+").Value; return result; }
public static SummaryResult ParseSummary(List<string> source) { SummaryResult result = new SummaryResult(); string summaryLine = source.Find(line => line.Trim().StartsWith("<test-results name=")); if (!string.IsNullOrEmpty(summaryLine)) { //<test-results name="redgreenplayground.dll" total="5" failures="4" not-run="1" date="2009-10-02" time="10:35:46"> string[] attributes = summaryLine.Split(' '); foreach (string keyValue in attributes) { if (keyValue.Contains("=")) { int delimiter = keyValue.IndexOf("="); string key = keyValue.Substring(0, delimiter); string value = keyValue.Substring(delimiter + 2, keyValue.Length - delimiter - 3); switch (key) { case "total": result.TotalCount = value; break; case "failures": result.FailCount = value; break; case "not-run": result.SkipCount = value; break; default: break; } } } result.PassCount = (int.Parse(result.TotalCount) - int.Parse(result.FailCount)).ToString(); result.Duration = String.Empty; } return result; }
/// <summary> /// Do the real work of running some tests /// </summary> /// <param name="assemblyPath">Where the class lives physically on the disk</param> /// <param name="filters">A set of filters to narrow the tests that should be run</param> private void RunTestsImpl(string assemblyPath, string filter) //params Filter<ITest>[] filters) { string consoleRunnerPath = GetConsoleRunnerExePath(); if (string.IsNullOrEmpty(consoleRunnerPath)) { return; } StreamReader sr = null; DateTime start = DateTime.Now; using (System.Diagnostics.Process p = new System.Diagnostics.Process()) { string arguments = string.Format(" {1} /xmlConsole \"{0}\"", assemblyPath, filter); p.StartInfo = new System.Diagnostics.ProcessStartInfo(consoleRunnerPath, arguments); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.Start(); sr = p.StandardOutput; } string line = sr.ReadLine(); List <string> rawResults = new List <string>(); while (line != null) { rawResults.Add(line); line = sr.ReadLine(); } TimeSpan duration = DateTime.Now - start; List <TestResult> parsedResults = NUnitParser.ParseTestResults(rawResults); SummaryResult summary = NUnitParser.ParseSummary(rawResults); summary.Duration = string.Format("{0}.{1}", duration.Seconds, duration.Milliseconds); foreach (TestResult testResult in parsedResults) { RaiseComplete(string.Empty, testResult); } RaiseAllComplete(summary); //while (line != "<!--This file represents the results of running a test suite-->") //{// eat the preamble // line = sr.ReadLine(); //} //line = sr.ReadLine(); //ResultParser parser = new ResultParser(); ////parser.ParseSummary //string rawResult = String.Empty; //while (line != null) //{ // StringBuilder result = new StringBuilder(); // ResultParser.ReadNextTextResult(sr, ref line, result); // rawResult = result.ToString(); // if (ResultParser.IsTestResult(rawResult)) // {// Only raise event for tests completed, not fixtures and the like. // RaiseComplete(result.ToString(), parser.ParseTest(rawResult)); // } //} //RaiseAllComplete(ResultParser.ParseSummary(rawResult)); }