コード例 #1
0
 /// <summary>
 /// Constructs an MbUnitCpp tests.
 /// </summary>
 /// <param name="testInfoData">Information about the test.</param>
 /// <param name="resolver"></param>
 public MbUnitCppTest(TestInfoData testInfoData, IStringResolver resolver)
     : base(testInfoData.Name, testInfoData.FakeCodeElement)
 {
     this.testInfoData = testInfoData;
     Id = testInfoData.GetId();
     Kind = GetKind(testInfoData.Kind);
     IsTestCase = !testInfoData.HasChildren;
     Metadata.AddAll(testInfoData.GetMetadata(resolver));
 }
コード例 #2
0
        /// <summary>
        /// Runs the targeted MbUnitCpp test.
        /// </summary>
        /// <param name="testInfoData">The information structure about the test to run.</param>
        /// <returns>The test step results.</returns>
        /// <exception cref="InvalidOperationException">Thrown if the repository is not valid, or if the specified structure points to a fixture.</exception>
        public TestStepResult RunTest(TestInfoData testInfoData)
        {
            if (!IsValid)
            {
                throw new InvalidOperationException("The target MbUnitCpp test library is not valid.");
            }
            if (testInfoData.HasChildren)
            {
                throw new InvalidOperationException("Not a valid test case.");
            }

            var                  function = (RunTestDelegate)Marshal.GetDelegateForFunctionPointer(procRunTest, typeof(RunTestDelegate));
            Position             position = testInfoData.Native.Position;
            NativeTestStepResult native;

            function(ref position, out native);
            return(new TestStepResult(native, this));
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
        /// <summary>
        /// Runs the targeted MbUnitCpp test.
        /// </summary>
        /// <param name="testInfoData">The information structure about the test to run.</param>
        /// <returns>The test step results.</returns>
        /// <exception cref="InvalidOperationException">Thrown if the repository is not valid, or if the specified structure points to a fixture.</exception>
        public TestStepResult RunTest(TestInfoData testInfoData)
        {
            if (!IsValid)
                throw new InvalidOperationException("The target MbUnitCpp test library is not valid.");
            if (testInfoData.HasChildren)
                throw new InvalidOperationException("Not a valid test case.");

            var function = (RunTestDelegate)Marshal.GetDelegateForFunctionPointer(procRunTest, typeof(RunTestDelegate));
            Position position = testInfoData.Native.Position;
            NativeTestStepResult native;
            function(ref position, out native);
            return new TestStepResult(native, this);
        }
コード例 #5
0
ファイル: RunTask.cs プロジェクト: dougrathbone/mbunit-v3
 private TestResult RunTestStep(ITestCommand testCommand, TestInfoData testStepInfo, TestStep parentTestStep, IProgressMonitor progressMonitor)
 {
     ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);
     TestStepResult testStepResult = repository.RunTest(testStepInfo);
     reporter.Run(testContext, testStepInfo, testStepResult);
     WriteToTestLog(testContext, testStepResult);
     testContext.AddAssertCount(testStepResult.AssertCount);
     progressMonitor.Worked(1);
     return testContext.FinishStep(testStepResult.TestOutcome, testStepResult.Duration);
 }