private void RunTestsWorker(TestExecutionTask[] executionTasks, TestExecutionOptions options) { Thread.CurrentThread.Name = "Test executor"; Thread.CurrentThread.IsBackground = true; _monitor.RecordMessage(TestMessageLevel.Informational, $"> Executing tests..."); _monitor.RecordMessage(TestMessageLevel.Informational, $"| Runner version is {Assembly.GetExecutingAssembly().GetName().Version}."); _monitor.RecordMessage(TestMessageLevel.Informational, $"| We are on {(Environment.Is64BitProcess ? "x64" : "x86")} platform."); if (!string.IsNullOrEmpty(options.RunSettingsPath)) { _monitor.RecordMessage(TestMessageLevel.Informational, $"| Using run settings {options.RunSettingsPath}."); } try { var context = new TestExecutionContext(_monitor, options); foreach (var executionTask in executionTasks) { NativeServices.ExecuteWithFileRedirection(executionTask.TestAdapterOptions, () => { if (TryLoadExecutor(executionTask.TestAdapterOptions.AssemblyPath, executionTask.TestAdapterOptions.ExtensionUri, out var testExecutor)) { _monitor.RecordMessage(TestMessageLevel.Informational, $">> Running executor: {testExecutor.GetType().FullName}..."); foreach (var testCaseGroup in executionTask.TestCases.GroupBy(p => p.Source)) { _monitor.RecordMessage(TestMessageLevel.Informational, $"|| Processing tests in: {testCaseGroup.Key}..."); context.TestRunDirectory = Path.GetDirectoryName(testCaseGroup.Key); Environment.CurrentDirectory = context.TestRunDirectory; testExecutor.RunTests(testCaseGroup.Convert(), context, context); } _monitor.RecordMessage(TestMessageLevel.Informational, $"<< Executor finished."); } else { foreach (var testCase in executionTask.TestCases) { var testResult = new Common.Models.TestResult() { TestCase = testCase, ErrorMessage = "Test executor is not loaded.", Outcome = Common.Models.TestOutcome.Skipped }; _monitor.RecordResult(testResult); } } }, (level, message) => _monitor.RecordMessage(level, "| " + message)); } _monitor.RecordMessage(TestMessageLevel.Informational, $"< Test execution finished."); } catch (Exception e) { _monitor.RecordMessage(TestMessageLevel.Error, $"< Could not execute tests.\r\n{e.GetDescription().PadLinesLeft("< ")}"); } }
public static Data.TestResult ToTestResult(this Common.Models.TestResult testResult, TestMethod testMethod, int sessionId) { return(new Data.TestResult() { Method = testMethod, Duration = testResult.Duration, Outcome = testResult.Outcome.ToTestState(), ErrorMessage = GetShortErrorMessage(testResult.ErrorMessage), StackTrace = StackItem.FromStackTrace(testResult.ErrorStackTrace), Output = testResult.Messages?.Length > 0 ? string.Join(Environment.NewLine, testResult.Messages.Select(p => p.Text)).Trim() : null, SessionId = sessionId }); }