private IEnumerable <TestResult> TryRunTests(string executable, string workingDir, string baseDir, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, CommandLineGenerator.Args arguments, string resultXmlFile, IProcessExecutor executor, TestResultSplitter splitter) { List <string> consoleOutput; if (_settings.UseNewTestExecutionFramework) { DebugUtils.AssertIsNotNull(executor, nameof(executor)); consoleOutput = RunTestExecutableWithNewFramework(executable, workingDir, arguments, executor, splitter); } else { consoleOutput = new TestProcessLauncher(_logger, _settings, isBeingDebugged) .GetOutputOfCommand(workingDir, executable, arguments.CommandLine, _settings.PrintTestOutput && !_settings.ParallelTestExecution, false, debuggedLauncher); } var remainingTestCases = arguments.TestCases.Except(splitter.TestResults.Select(tr => tr.TestCase)); return(CollectTestResults(remainingTestCases, resultXmlFile, consoleOutput, baseDir, splitter.CrashedTestCase)); }
private List <string> RunTestExecutableWithNewFramework(string executable, string workingDir, CommandLineGenerator.Args arguments, IProcessExecutor executor, TestResultSplitter splitter) { string pathExtension = _settings.GetPathExtension(executable); bool printTestOutput = _settings.PrintTestOutput && !_settings.ParallelTestExecution; if (printTestOutput) { _logger.LogInfo( $"{_threadName}>>>>>>>>>>>>>>> Output of command '" + executable + " " + arguments.CommandLine + "'"); } Action <string> reportOutputAction = line => { splitter.ReportLine(line); if (printTestOutput) { _logger.LogInfo(line); } }; executor.ExecuteCommandBlocking( executable, arguments.CommandLine, workingDir, pathExtension, reportOutputAction); splitter.Flush(); if (printTestOutput) { _logger.LogInfo($"{_threadName}<<<<<<<<<<<<<<< End of Output"); } var consoleOutput = new List <string>(); new TestDurationSerializer().UpdateTestDurations(splitter.TestResults); _logger.DebugInfo( $"{_threadName}Reported {splitter.TestResults.Count} test results to VS during test execution, executable: '{executable}'"); foreach (TestResult result in splitter.TestResults) { if (!_schedulingAnalyzer.AddActualDuration(result.TestCase, (int)result.Duration.TotalMilliseconds)) { _logger.LogWarning($"{_threadName}TestCase already in analyzer: {result.TestCase.FullyQualifiedName}"); } } return(consoleOutput); }
// ReSharper disable once UnusedParameter.Local private void RunTestsFromExecutable(string executable, string workingDir, IEnumerable <TestCase> allTestCases, IEnumerable <TestCase> testCasesToRun, string baseDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor) { string resultXmlFile = Path.GetTempFileName(); var serializer = new TestDurationSerializer(); var generator = new CommandLineGenerator(allTestCases, testCasesToRun, executable.Length, userParameters, resultXmlFile, _settings); foreach (CommandLineGenerator.Args arguments in generator.GetCommandLines()) { if (_canceled) { break; } var splitter = new TestResultSplitter(arguments.TestCases, _logger, baseDir, _frameworkReporter); var results = RunTests(executable, workingDir, baseDir, isBeingDebugged, debuggedLauncher, arguments, resultXmlFile, executor, splitter).ToArray(); Stopwatch stopwatch = Stopwatch.StartNew(); _frameworkReporter.ReportTestsStarted(results.Select(tr => tr.TestCase)); _frameworkReporter.ReportTestResults(results); stopwatch.Stop(); if (results.Length > 0) { _logger.DebugInfo($"{_threadName}Reported {results.Length} test results to VS, executable: '{executable}', duration: {stopwatch.Elapsed}"); } serializer.UpdateTestDurations(results); foreach (TestResult result in results) { if (!_schedulingAnalyzer.AddActualDuration(result.TestCase, (int)result.Duration.TotalMilliseconds)) { _logger.DebugWarning("TestCase already in analyzer: " + result.TestCase.FullyQualifiedName); } } } }
private IEnumerable <TestResult> RunTests(string executable, string workingDir, string baseDir, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, CommandLineGenerator.Args arguments, string resultXmlFile, IProcessExecutor executor, TestResultSplitter splitter) { try { return(TryRunTests(executable, workingDir, baseDir, isBeingDebugged, debuggedLauncher, arguments, resultXmlFile, executor, splitter)); } catch (Exception e) { LogExecutionError(_logger, executable, workingDir, arguments.CommandLine, e); return(new TestResult[0]); } }