public void ConvertExceptionToVSTestResult() { LogEntryException exception = new LogEntryException("C string: some error", new SourceFileInfo("unknown location", 0)); exception.LastCheckpoint = new SourceFileInfo("boostunittestsample.cpp", 13); exception.CheckpointDetail = "Going to throw an exception"; BoostTestResult testCaseResult = new BoostTestResultBuilder(). For(this.TestCase). Aborted(). Duration(0). Log(exception). Build(); VSTestResult result = testCaseResult.AsVSTestResult(this.TestCase); AssertVSTestModelProperties(result); Assert.That(result.Outcome, Is.EqualTo(TestOutcome.Failed)); // A 0 duration should list as 1 tick to avoid UI issues in the test adapter Assert.That(result.Duration, Is.EqualTo(TimeSpan.FromTicks(1))); AssertVsTestModelError(result, exception); Assert.That(result.Messages.Count, Is.EqualTo(1)); TestResultMessage message = result.Messages.First(); Assert.That(message.Category, Is.EqualTo(TestResultMessage.StandardErrorCategory)); }
/// <summary> /// Formats a LogEntryException to append to test result string /// </summary> /// <param name="exception">The exception to format</param> /// <param name="sb">The StringBuilder which will host the output</param> /// <returns>sb</returns> private static StringBuilder FormatException(LogEntryException exception, StringBuilder sb) { if (exception.LastCheckpoint != null) { sb.Append(Environment.NewLine); AppendSourceInfo(exception.LastCheckpoint, sb); sb.Append("last checkpoint: ").Append(exception.CheckpointDetail); } return sb; }
/// <summary> /// Parse a LogException from the provided node. /// </summary> /// <param name="node">The Xml node which contains exception information.</param> /// <returns>A LogEntryException populated from the provided Xml node.</returns> private static LogEntryException ParseTestCaseLogException(XmlNode node) { LogEntryException exception = new LogEntryException(); foreach (XmlNode child in node.ChildNodes) { if (child.NodeType == XmlNodeType.CDATA) { exception.Detail = child.InnerText; } else if ((child.NodeType == XmlNodeType.Element) && (child.Name == Xml.LastCheckpoint)) { exception.LastCheckpoint = ParseSourceInfo(child); exception.CheckpointDetail = child.InnerText; } } return exception; }
/// <summary> /// Tests the provided LogEntryException's properties against the expected values /// </summary> /// <param name="entry">The LogEntryException to test</param> /// <param name="checkpointInfo">The expected source file information for the exception</param> /// <param name="checkpointMessage">The expected checkpoint message</param> private void AssertLogEntryExceptionDetails(LogEntryException entry, SourceFileInfo checkpointInfo, string checkpointMessage) { AssertSourceInfoDetails(checkpointInfo, entry.LastCheckpoint); Assert.That(entry.CheckpointDetail, Is.EqualTo(checkpointMessage)); }