public ReportPortalReporterMessageHandler(IRunnerLogger logger) { Logger = logger; var jsonPath = Path.GetDirectoryName(new Uri(typeof(ReportPortalReporter).Assembly.CodeBase).LocalPath) + "/ReportPortal.config.json"; Logger.LogMessage($"ReportPortal json config: {jsonPath}"); _config = new ConfigurationBuilder().AddJsonFile(jsonPath).AddEnvironmentVariables().Build(); Bridge.Service = new Service(new Uri(_config.GetValue <string>(ConfigurationPath.ServerUrl)), _config.GetValue <string>(ConfigurationPath.ServerProject), _config.GetValue <string>(ConfigurationPath.ServerAuthenticationUuid)); Execution.TestAssemblyStartingEvent += TestAssemblyExecutionStarting; Execution.TestAssemblyFinishedEvent += TestAssemblyExecutionFinished; Execution.TestCollectionStartingEvent += HandleTestCollectionStarting; Execution.TestCollectionFinishedEvent += HandleTestCollectionFinished; Execution.TestStartingEvent += HandleTestStarting; Execution.TestPassedEvent += HandlePassed; Execution.TestSkippedEvent += HandleSkipped; Execution.TestFailedEvent += HandleFailed; Execution.TestOutputEvent += Execution_TestOutputEvent; }
/// <summary> /// Logs a normal-priority message. /// </summary> /// <param name="logger">The logger</param> /// <param name="message">The message to be logged</param> public static void LogMessage( this IRunnerLogger logger, string message) { Guard.ArgumentNotNull(logger); Guard.ArgumentNotNull(message); logger.LogMessage(StackFrameInfo.None, message); }
/// <summary> /// Logs a normal-priority formatted message. /// </summary> /// <param name="logger">The logger</param> /// <param name="messageFormat">The format of the message to be logged</param> /// <param name="args">The format arguments</param> public static void LogMessage( this IRunnerLogger logger, string messageFormat, params object?[] args) { Guard.ArgumentNotNull(logger); Guard.ArgumentNotNull(messageFormat); logger.LogMessage(StackFrameInfo.None, string.Format(messageFormat, args)); }
void HandleTestAssemblyFinished(MessageHandlerArgs <ITestAssemblyFinished> args) { ExecutionSummary.Total = args.Message.TestsRun; ExecutionSummary.Failed = args.Message.TestsFailed; ExecutionSummary.Skipped = args.Message.TestsSkipped; ExecutionSummary.Time = args.Message.ExecutionTime; ExecutionSummary.Errors = errors; completionCallback?.Invoke(Path.GetFileNameWithoutExtension(args.Message.TestAssembly.Assembly.AssemblyPath), ExecutionSummary); if (_logger != null) { _logger.LogMessage("DelegatingExecutionSummarySink.HandleTestAssemblyFinished"); } Finished.Set(); }
int RunProject(XunitProject project, bool serialize, bool?parallelizeAssemblies, bool?parallelizeTestCollections, int?maxThreadCount, bool diagnosticMessages, bool noColor, AppDomainSupport?appDomains, bool failSkips, bool stopOnFail, bool internalDiagnosticMessages) { XElement assembliesElement = null; var clockTime = Stopwatch.StartNew(); var xmlTransformers = TransformFactory.GetXmlTransformers(project); var needsXml = xmlTransformers.Count > 0; if (!parallelizeAssemblies.HasValue) { parallelizeAssemblies = project.All(assembly => assembly.Configuration.ParallelizeAssemblyOrDefault); } logger.LogMessage($"NeedsXml: {needsXml}"); if (needsXml) { assembliesElement = new XElement("assemblies"); } var originalWorkingFolder = Directory.GetCurrentDirectory(); if (parallelizeAssemblies.GetValueOrDefault()) { var tasks = project.Assemblies.Select(assembly => Task.Run(() => ExecuteAssembly(consoleLock, assembly, serialize, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, appDomains, failSkips, stopOnFail, project.Filters, internalDiagnosticMessages))); var results = Task.WhenAll(tasks).GetAwaiter().GetResult(); foreach (var assemblyElement in results.Where(result => result != null)) { logger.LogMessage($"AssembliesElement: {assembliesElement?.ToString()}"); assembliesElement.Add(assemblyElement); } } else { foreach (var assembly in project.Assemblies) { var assemblyElement = ExecuteAssembly(consoleLock, assembly, serialize, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, appDomains, failSkips, stopOnFail, project.Filters, internalDiagnosticMessages); if (assemblyElement != null) { logger.LogMessage($"AssembliesElement before add assembly {assembly.AssemblyFilename}: {assembliesElement?.ToString()}"); assembliesElement.Add(assemblyElement); } } } clockTime.Stop(); logger.LogMessage($"AssembliesElement before adding timestamp: {assembliesElement?.ToString()}"); if (assembliesElement != null) { assembliesElement.Add(new XAttribute("timestamp", DateTime.Now.ToString(CultureInfo.InvariantCulture))); } if (completionMessages.Count > 0) { reporterMessageHandler.OnMessage(new TestExecutionSummary(clockTime.Elapsed, completionMessages.OrderBy(kvp => kvp.Key).ToList())); } Directory.SetCurrentDirectory(originalWorkingFolder); xmlTransformers.ForEach(transformer => transformer(assembliesElement)); return(failed ? 1 : completionMessages.Values.Sum(summary => summary.Failed)); }
XElement CreateTestResultElement(ITestResultMessage testResult, string resultText) { ITest test = testResult.Test; ITestCase testCase = testResult.TestCase; ITestMethod testMethod = testCase.TestMethod; ITestClass testClass = testMethod.TestClass; var collectionElement = GetTestCollectionElement(testClass.TestCollection); var testResultElement = new XElement("test", new XAttribute("name", XmlEscape(test.DisplayName)), new XAttribute("type", testClass.Class.Name), new XAttribute("method", testMethod.Method.Name), new XAttribute("time", testResult.ExecutionTime.ToString(CultureInfo.InvariantCulture)), new XAttribute("result", resultText) ); var testOutput = testResult.Output; if (!string.IsNullOrWhiteSpace(testOutput)) { testResultElement.Add(new XElement("output", new XCData(testOutput))); } ISourceInformation sourceInformation = testCase.SourceInformation; if (sourceInformation != null) { var fileName = sourceInformation.FileName; if (fileName != null) { testResultElement.Add(new XAttribute("source-file", fileName)); } var lineNumber = sourceInformation.LineNumber; if (lineNumber != null) { testResultElement.Add(new XAttribute("source-line", lineNumber.GetValueOrDefault())); } } var traits = testCase.Traits; if (traits != null && traits.Count > 0) { var traitsElement = new XElement("traits"); foreach (var keyValuePair in traits) { foreach (var val in keyValuePair.Value) { traitsElement.Add( new XElement("trait", new XAttribute("name", XmlEscape(keyValuePair.Key)), new XAttribute("value", XmlEscape(val)) ) ); } } testResultElement.Add(traitsElement); } collectionElement.Add(testResultElement); if (_logger != null) { _logger.LogMessage($"collectionElement: {collectionElement}"); } return(testResultElement); }
/// <summary> /// Logs a normal-priority formatted message with stack frame. /// </summary> /// <param name="logger">The logger</param> /// <param name="stackFrame">The stack frame information</param> /// <param name="messageFormat">The format of the message to be logged</param> /// <param name="args">The format arguments</param> public static void LogMessage(this IRunnerLogger logger, StackFrameInfo stackFrame, string messageFormat, params object[] args) { logger.LogMessage(stackFrame, string.Format(messageFormat, args)); }
/// <summary> /// Logs a normal-priority message. /// </summary> /// <param name="logger">The logger</param> /// <param name="message">The message to be logged</param> public static void LogMessage(this IRunnerLogger logger, string message) { logger.LogMessage(StackFrameInfo.None, message); }