private void TestFinished(TestOutcome outcome, string fixtureName, string testName, int assertCount, ulong durationNanosec, string reason, TestContextCallback callback) { ITestCommand fixtureCommand; if (!testCommandsByName.TryGetValue(fixtureName, out fixtureCommand)) { return; } ITestCommand testCommand; ITestContext testContext = null; if (testCommandsByName.TryGetValue(fixtureName + @"." + testName, out testCommand)) { if (testContextStack.Peek().TestStep.Test == testCommand.Test) { // Remove our test context from the stack testContext = testContextStack.Pop(); } } ITestContext fixtureContext = GetFixtureContext(fixtureCommand); if (testCommand != null) { if (testContext == null) { testContext = testCommand.StartPrimaryChildStep(fixtureContext.TestStep); testContext.LifecyclePhase = LifecyclePhases.Execute; progressMonitor.SetStatus(testCommand.Test.Name); } TimeSpan?duration = null; if (durationNanosec > 0) { // A tick is equal to 100 nanoseconds duration = TimeSpan.FromTicks((long)(durationNanosec / 100UL)); } if (callback != null) { callback(testContext); } testContext.AddAssertCount(assertCount); testContext.FinishStep(outcome, duration); progressMonitor.Worked(1); } else if (!String.IsNullOrEmpty(reason)) { MarkupStreamWriter log = fixtureContext.LogWriter.Failures; using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName)) { log.Write(reason); } } }
private void Launch(bool doNoRun) { MarkupStreamWriter logStreamWriter = TestLog.Default; var launcher = new TestLauncher(); launcher.TestProject.TestPackage = testPackage; launcher.Logger = new MarkupStreamLogger(logStreamWriter); launcher.TestExecutionOptions.FilterSet = new FilterSet <ITestDescriptor>(new OrFilter <ITestDescriptor>(filters)); launcher.TestProject.TestRunnerFactoryName = TestRunnerFactoryName; string reportDirectory = SpecialPathPolicy.For <SampleRunner>().GetTempDirectory().FullName; launcher.TestProject.ReportDirectory = reportDirectory; launcher.TestProject.ReportNameFormat = "SampleRunnerReport"; launcher.ReportFormatterOptions.AddProperty(@"SaveAttachmentContents", @"false"); launcher.AddReportFormat(@"Text"); // Disabled because the Xml can get really big and causes problems if the sample runner is used frequently. //launcher.AddReportFormat("Xml"); launcher.DoNotRun = doNoRun; GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => launcher.TestRunnerOptions.AddProperty(x.Key, x.Value)); using (logStreamWriter.BeginSection("Log Output")) result = launcher.Run(); using (logStreamWriter.BeginSection("Text Report")) { foreach (string reportPath in result.ReportDocumentPaths) { string extension = Path.GetExtension(reportPath); if (extension == ".txt") { logStreamWriter.WriteLine(File.ReadAllText(reportPath)); } else if (extension == ".xml") { logStreamWriter.Container.AttachXml(null, File.ReadAllText(reportPath)); } File.Delete(reportPath); } } }
public static void Snapshot(IE ie, string caption, MarkupStreamWriter logStreamWriter) { using (logStreamWriter.BeginSection(caption)) { logStreamWriter.Write("Url: "); using (logStreamWriter.BeginMarker(Marker.Link(ie.Url))) logStreamWriter.Write(ie.Url); logStreamWriter.WriteLine(); logStreamWriter.EmbedImage(caption + ".png", new CaptureWebPage(ie).CaptureWebPageImage(false, false, 100)); } }
private static void ConfigureProcessTaskForLogging(ProcessTask task, MarkupStreamWriter writer) { task.Started += delegate { writer.BeginSection(String.Format("Run Process: {0} {1}", task.ExecutablePath, task.Arguments)); writer.WriteLine("Working Directory: {0}", task.WorkingDirectory); writer.BeginMarker(Marker.Monospace); }; task.ConsoleOutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data != null) { writer.WriteLine(e.Data); } }; task.ConsoleErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { if (e.Data != null) { writer.WriteLine(e.Data); } }; task.Aborted += delegate { if (task.IsRunning) { writer.BeginSection("Abort requested. Killing the process!").Dispose(); } }; task.Terminated += delegate { writer.End(); writer.WriteLine("Exit Code: {0}", task.ExitCode); writer.End(); }; }
void ITestListener.OnTestFailed(object sender, TestResultEventArgs args) { TestFinished(TestOutcome.Failed, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason, delegate(ITestContext context) { if (args.Failure != null) { MarkupStreamWriter log = context.LogWriter.Failures; using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName)) { if (!String.IsNullOrEmpty(args.Failure.Expected)) { log.WriteLine(args.Failure.Expected); } if (!String.IsNullOrEmpty(args.Failure.Actual)) { log.WriteLine(args.Failure.Actual); } if (!String.IsNullOrEmpty(args.Failure.Message)) { log.WriteLine(args.Failure.Message); } } using (log.BeginSection(Resources.CSUnitTestController_ResultStackTraceSectionName)) { using (log.BeginMarker(Marker.StackTrace)) { log.Write(args.Failure.StackTrace); } } } }); Interlocked.Increment(ref fixtureFailureCount); }
void ITestListener.OnTestError(object sender, TestResultEventArgs args) { TestFinished(TestOutcome.Error, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason, delegate(ITestContext context) { if (!String.IsNullOrEmpty(args.Reason)) { MarkupStreamWriter log = context.LogWriter.Failures; using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName)) { log.Write(args.Reason); } } }); Interlocked.Increment(ref fixtureErrorCount); }
/// <summary> /// Writes the assertion failure to a test log stream. /// </summary> /// <param name="writer">The test log stream.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception> public virtual void WriteTo(MarkupStreamWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } using (writer.BeginMarker(Marker.AssertionFailure)) { using (writer.BeginSection(description)) { WriteDetails(writer); foreach (AssertionFailure innerFailure in innerFailures) { innerFailure.WriteTo(writer); } } } }
private static void LogMessage(MarkupDocumentWriter markupDocumentWriter, string actionDescription, TestOutcome outcome, string message, Exception ex) { if (string.IsNullOrEmpty(message) && ex == null) { return; } MarkupStreamWriter stream = GetLogStreamWriterForOutcome(markupDocumentWriter, outcome); using (actionDescription != null ? stream.BeginSection(actionDescription) : null) { if (!string.IsNullOrEmpty(message)) { stream.WriteLine(message); } if (ex != null) { stream.WriteException(StackTraceFilter.FilterException(ex)); } } }
internal override void WriteToImpl(MarkupStreamWriter writer) { using (writer.BeginSection(name)) base.WriteToImpl(writer); }