/// <summary>
        /// Reports an assertion failure.
        /// </summary>
        /// <param name="testContext"></param>
        /// <param name="testInfoData"></param>
        /// <param name="testStepResult"></param>
        public void Run(ITestContext testContext, TestInfoData testInfoData, TestStepResult testStepResult)
        {
            if (testStepResult.TestOutcome == TestOutcome.Failed)
            {
                MbUnitCppAssertionFailure failure = testStepResult.Failure;
                var builder = new AssertionFailureBuilder(failure.Description);

                if (failure.HasExpectedValue && failure.HasActualValue && failure.Diffing)
                {
                    builder.AddRawExpectedAndActualValuesWithDiffs(failure.ExpectedValue, failure.ActualValue);
                }
                else if (failure.HasUnexpectedValue && failure.HasActualValue && failure.Diffing)
                {
                    builder.AddRawLabeledValuesWithDiffs("Unexpected Value", failure.UnexpectedValue, "Actual Value", failure.ActualValue);
                }
                else
                {
                    if (failure.HasExpectedValue)
                        builder.AddRawExpectedValue(failure.ExpectedValue);

                    if (failure.HasActualValue)
                        builder.AddRawActualValue(failure.ActualValue);

                    if (failure.HasUnexpectedValue)
                        builder.AddRawLabeledValue("Unexpected Value", failure.UnexpectedValue);
                }

                foreach (var extra in failure.ExtraLabeledValues)
                {
                    builder.AddRawLabeledValue(extra.First, extra.Second);
                }

                if (failure.Message.Length > 0)
                    builder.SetMessage(failure.Message);

                builder.SetStackTrace(testInfoData.GetStackTraceData(failure.Line));
                builder.ToAssertionFailure().WriteTo(testContext.LogWriter.Failures);
            }
        }
Exemple #2
0
 private static void WriteToTestLog(ITestContext testContext, TestStepResult testStepResult)
 {
     if (testStepResult.TestLogContents.Length > 0)
         testContext.LogWriter.Default.Write(testStepResult.TestLogContents);
 }