/// <summary> /// Starts OpenCover.Console.exe to start CodeCoverage session. /// </summary> /// <returns>Test results (trx) and OpenCover results files' paths</returns> public Tuple <string, string> Execute() { var openCoverStartInfo = GetOpenCoverProcessInfo(); Process process = Process.Start(openCoverStartInfo); var consoleOutputReaderBuilder = new StringBuilder(); // TODO: See if this loop has any performance bottlenecks while (true) { if (process.HasExited) { break; } string nextLine = process.StandardOutput.ReadLine(); if (!String.IsNullOrWhiteSpace(nextLine) && nextLine.StartsWith("Results File:")) { _testResultsFile = nextLine.Replace("Results File: ", ""); } Debug.WriteLine(nextLine); consoleOutputReaderBuilder.AppendLine(nextLine); } process.WaitForExit(); Debug.WriteLine(process.StandardError.ReadToEnd()); IDEHelper.OpenFile(_package.DTE, _testResultsFile); return(new Tuple <string, string>(_testResultsFile, _openCoverResultsFile)); }
internal override void UpdateTestMethodsExecution(IEnumerable <TestClass> tests) { var executedTests = tests.SelectMany(t => t.TestMethods) .Join(_execution, t => new { d = t.Class.DLLPath, n = t.FullyQualifiedName }, t => new { d = t.Item1, n = t.Item2.MethodName }, (testMethod, result) => new { TestMethod = testMethod, Result = result }); foreach (var test in executedTests) { test.TestMethod.ExecutionResult = test.Result.Item2; } if (File.Exists(_testResultsFile)) { IDEHelper.OpenFile(OpenCoverUIPackage.Instance.DTE, _testResultsFile); } }
/// <summary> /// TreeViewItem double click event handler. /// Opens the corresponding file if the clicked node represents either a class or a method. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param> private void TreeViewItemDoubleClicked(object sender, MouseButtonEventArgs e) { Method method = null; var treeView = sender as ICSharpCode.TreeView.SharpTreeView; if (treeView.SelectedItem is ClassNode) { method = (treeView.SelectedItem as ClassNode).Class.Methods.FirstOrDefault(); } else if (treeView.SelectedItem is MethodNode) { method = (treeView.SelectedItem as MethodNode).Method; } if (method != null) { var sequencePoints = CoverageSession.GetSequencePoints().Where(ig => ig.Key == method.FileRef.UniqueId); var coveredFiles = CoverageSession.GetFiles(); if (coveredFiles != null) { try { var file = coveredFiles.FirstOrDefault(f => f.UniqueId == method.FileRef.UniqueId); IDEHelper.CloseFile(_package.DTE, file.FullPath); _fileOpening = true; _lastSelectedFile = file.FullPath; IDEHelper.OpenFile(_package.DTE, file.FullPath); IDEHelper.GoToLine(_package.DTE, method.SequencePoints.FirstOrDefault().StartLine); } catch { } } e.Handled = true; } }