private void GetTestResults(string testLog) { try { var testFile = testLog.Replace(@"""", string.Empty); if (!File.Exists(testFile)) { return; } TestResult = testFile.LoadTestsFromFile(); } catch (Exception exp) { TestResult = null; Trace.TraceError("Unknown Exception Occurred On Getting Test result {0}", exp); } }
public async Task ExecuteTests(string app, string filter) { try { _currentDateTime = DateTime.Now; var testResultFile = $@"""{LogDir}test_report_{_currentDateTime:yyyyMdhhmmss}.xml"""; LastTestExecutionStatus = TestExecutionStatus.Success; TestResult = null; var methodBuilder = new StringBuilder(ShuffleTests); if (!string.IsNullOrWhiteSpace(filter)) { methodBuilder.Append($" {TestCaseFilter}") .Append($"\"{filter}\""); } if (!string.IsNullOrWhiteSpace(LogDir)) { if (!Directory.Exists(LogDir)) { Directory.CreateDirectory(LogDir); } methodBuilder.Append($" --gtest_output=xml:{testResultFile}"); } var processInfo = new ProcessStartInfo(app) { Arguments = methodBuilder.ToString(), UseShellExecute = false, ErrorDialog = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, WindowStyle = ProcessWindowStyle.Hidden }; await Task.Run(() => { lock (TestTimeoutLock) { using (_currentProcess = new Process { StartInfo = processInfo, EnableRaisingEvents = true }) { _currentProcess.OutputDataReceived += CurrentProcessOnOutputDataReceived; _currentProcess.ErrorDataReceived += CurrentProcessOnOutputDataReceived; _currentProcess.Start(); _currentProcess.BeginOutputReadLine(); _currentProcess.BeginErrorReadLine(); if (EnableTestTimeout) { _currentProcess.WaitForExit((int)TestTimeout); if (!_currentProcess.HasExited) { KillProcess(_currentProcess); } } else { _currentProcess.WaitForExit(); } if (LastTestExecutionStatus != TestExecutionStatus.Failed && LastTestExecutionStatus != TestExecutionStatus.Timeout) { LastTestExecutionStatus = TestStatusList.ContainsKey(_currentProcess.ExitCode) ? TestStatusList[_currentProcess.ExitCode] : _currentProcess.ExitCode < 0 ? TestExecutionStatus.Failed : TestExecutionStatus.Timeout; } _currentProcess.OutputDataReceived -= CurrentProcessOnOutputDataReceived; _currentProcess.ErrorDataReceived -= CurrentProcessOnOutputDataReceived; GetTestResults(testResultFile); } } }); } catch (Exception e) { Trace.TraceError("{0} - {1}", e.Message, e); throw; } }
/// <summary> /// Maps result types from JUnit into instance of drop models with configuration /// </summary> /// <param name="source">Instance of test results from deserialised JUnit input</param> /// <param name="destination">Instance to map and merge results into</param> /// <param name="inputConfiguration">User configured input for current source</param> public static void Map(Testsuites source, TestRunDrop destination, ReportInput inputConfiguration = null) { foreach (var testsuite in source.Testsuite) { var started = DateTimeOffset.Parse(testsuite.Timestamp); var finished = started + TimeSpan.FromMilliseconds(double.Parse(testsuite.Time)); if (destination.Started is null || destination.Started > started) { destination.Started = started; } if (destination.Finished is null || destination.Finished < finished) { destination.Finished = finished; } var key = inputConfiguration?.GroupTitle ?? testsuite.Package; foreach (var testCase in testsuite.Testcase) { TestResultSetDrop drop; if (destination.ResultSets.TryGetValue(key, out var existingDrop)) { drop = existingDrop; } else { drop = new TestResultSetDrop { Source = key, Results = new List <TestResultDrop>(), }; destination.ResultSets.Add(drop); } var testCaseDrop = new TestCaseDrop { Source = testsuite.Package, DisplayName = string.IsNullOrEmpty(inputConfiguration?.TestSuffix) ? testCase.Name : $"{testCase.Name}{inputConfiguration.TestSuffix}", FullyQualifiedName = $"{testCase.Classname}.{testCase.Classname}", Id = null, ExecutorUri = null, }; var duration = TimeSpan.FromMilliseconds(double.Parse(testCase.Time)); var outcome = MapOutcome(testCase, drop, destination.TestRunStatistics); var resultDrop = new TestResultDrop { StartTime = null, EndTime = null, Duration = duration, Outcome = outcome, TestCase = testCaseDrop, ComputerName = testsuite.Hostname, AttachmentSets = null, DisplayName = testCase.Name }; MapOutputToResult(testCase, resultDrop); destination.TestRunStatistics.ExecutedTestsCount++; destination.ElapsedTimeInRunningTests += duration; drop.Duration += duration; drop.ExecutedTestsCount++; drop.Results.Add(resultDrop); } } }