private void ReportTestResult(Model.TestResult testResult) { Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult result = testResult.ToVsTestResult(); Throttle.Execute(delegate { // This is part of a workaround for a Visual Studio bug. See above. FrameworkHandle.RecordResult(result); }); FrameworkHandle.RecordEnd(result.TestCase, result.Outcome); }
private void ReportTestResult(TestResult testResult) { VsTestResult result = testResult.ToVsTestResult(); _throttle.Execute(delegate { // This is part of a workaround for a Visual Studio bug. See above. _frameworkHandle.RecordResult(result); }); _frameworkHandle.RecordEnd(result.TestCase, result.Outcome); }
public void WriteTestResult(Guid executionId, VsTestResult testResult) { if (!inResults) { throw new InvalidOperationException("WriteStartTestResults() not called"); } xml.WriteStartElement("UnitTestResult", XmlNamespace); xml.WriteAttributeString("executionId", executionId.ToString()); xml.WriteAttributeString("testId", testResult.TestCase.Id.ToString()); xml.WriteAttributeString("testName", testResult.DisplayName); xml.WriteAttributeString("computerName", testResult.ComputerName); xml.WriteAttributeString("duration", testResult.Duration.ToString("c", CultureInfo.InvariantCulture)); xml.WriteAttributeString("startTime", testResult.StartTime.ToString("O", CultureInfo.InvariantCulture)); xml.WriteAttributeString("endTime", testResult.EndTime.ToString("O", CultureInfo.InvariantCulture)); xml.WriteAttributeString("testType", TestType); xml.WriteAttributeString("outcome", VsTestOutcomeHelper.GetOutcomeString(testResult.Outcome)); xml.WriteAttributeString("testListId", TestListNotInAListId); xml.WriteAttributeString("relativeResultsDirectory", executionId.ToString()); bool hasErrorMessage = !string.IsNullOrEmpty(testResult.ErrorMessage); bool hasStackTrace = !string.IsNullOrEmpty(testResult.ErrorStackTrace); bool hasStdOut = false; if (hasErrorMessage || hasStackTrace || hasStdOut) { xml.WriteStartElement("Output", XmlNamespace); if (hasErrorMessage || hasStackTrace) { xml.WriteStartElement("ErrorInfo", XmlNamespace); if (hasErrorMessage) { xml.WriteElementString("Message", XmlNamespace, testResult.ErrorMessage); } if (hasStackTrace) { xml.WriteElementString("StackTrace", XmlNamespace, testResult.ErrorStackTrace); } xml.WriteEndElement(); // ErrorInfo } if (hasStdOut) { // TODO: Figure out how to include StdOut messages //xml.WriteElementString("StdOut", XmlNamespace, ((Microsoft.VisualStudio.TestPlatform.ObjectModel.AttachmentSet)testResult.Attachments[0]).; } xml.WriteEndElement(); // Output } xml.WriteEndElement(); // UnitTestResult }
public void WriteTestEntry(Guid executionId, VsTestResult testResult) { if (!inTestEntries) { throw new InvalidOperationException("WriteStartTestEntries() not called"); } xml.WriteStartElement("TestEntry", XmlNamespace); xml.WriteAttributeString("testId", testResult.TestCase.Id.ToString()); xml.WriteAttributeString("executionId", executionId.ToString()); xml.WriteAttributeString("testListId", TestListNotInAListId); xml.WriteEndElement(); // TestEntry }
public void WriteTestDefinition(Guid executionId, VsTestResult testResult) { if (!inTestDefinitions) { throw new InvalidOperationException("WriteStartTestDefinitions() not called"); } // TODO: See if we can get the class name passed into TestResult string className = testResult.TestCase.FullyQualifiedName; int lastDot; if ((lastDot = testResult.TestCase.FullyQualifiedName.LastIndexOf('.')) != -1) { className = testResult.TestCase.FullyQualifiedName.Substring(0, lastDot); } xml.WriteStartElement("UnitTest", XmlNamespace); xml.WriteAttributeString("name", testResult.DisplayName); xml.WriteAttributeString("storage", testResult.TestCase.CodeFilePath); xml.WriteAttributeString("id", testResult.TestCase.Id.ToString()); xml.WriteStartElement("Execution", XmlNamespace); xml.WriteAttributeString("id", executionId.ToString()); xml.WriteEndElement(); // Execution xml.WriteStartElement("TestMethod", XmlNamespace); xml.WriteAttributeString("codeBase", testResult.TestCase.CodeFilePath); xml.WriteAttributeString("adapterTypeName", testResult.TestCase.ExecutorUri.ToString()); xml.WriteAttributeString("className", className); xml.WriteAttributeString("name", testResult.TestCase.DisplayName); xml.WriteEndElement(); // TestMethod if (testResult.TestCase.Traits.Any()) { xml.WriteStartElement("Properties", XmlNamespace); foreach (var trait in testResult.TestCase.Traits) { xml.WriteStartElement("Property", XmlNamespace); xml.WriteElementString("Key", XmlNamespace, trait.Name); xml.WriteElementString("Value", XmlNamespace, trait.Value); xml.WriteEndElement(); // Property } xml.WriteEndElement(); // Properties } // TODO: TestCategory xml.WriteEndElement(); // UnitTest }
/// <summary> /// Adds a test result to the database /// </summary> /// <param name="test">Test result</param> public void AddTestResult(Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult test) { if (firstTest) { firstTest = false; // If the testRun record was already created then grab it else create a new one int testRunId; if (!String.IsNullOrEmpty(GetParameter("PnPTestRunId")) && Int32.TryParse(GetParameter("PnPTestRunId"), out testRunId)) { testRun = context.TestRunSet.Find(testRunId); } else { AddTestSetRecord(); } // Bring status to "running" testRun.Status = RunStatus.Running; } // Store the test result TestResult tr = new TestResult() { ComputerName = test.ComputerName, TestCaseName = !string.IsNullOrEmpty(test.DisplayName) ? test.DisplayName : test.TestCase.FullyQualifiedName, Duration = test.Duration, ErrorMessage = test.ErrorMessage, ErrorStackTrace = test.ErrorStackTrace, StartTime = test.StartTime, EndTime = test.EndTime, }; switch (test.Outcome) { case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.None: tr.Outcome = Outcome.None; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Passed: tr.Outcome = Outcome.Passed; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Failed: tr.Outcome = Outcome.Failed; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.Skipped: tr.Outcome = Outcome.Skipped; break; case Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome.NotFound: tr.Outcome = Outcome.NotFound; break; default: tr.Outcome = Outcome.None; break; } if (test.Messages != null && test.Messages.Count > 0) { foreach (var message in test.Messages) { tr.TestResultMessages.Add(new TestResultMessage() { Category = message.Category, Text = message.Text, }); } } testRun.TestResults.Add(tr); SaveChanges(); }