当前位置: 首页>>代码示例>>C#>>正文


C# ITestContext.FinishStep方法代码示例

本文整理汇总了C#中ITestContext.FinishStep方法的典型用法代码示例。如果您正苦于以下问题:C# ITestContext.FinishStep方法的具体用法?C# ITestContext.FinishStep怎么用?C# ITestContext.FinishStep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITestContext的用法示例。


在下文中一共展示了ITestContext.FinishStep方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogMethodResultAndFinishStep

        private static bool LogMethodResultAndFinishStep(ITestContext testContext, XunitMethodResult result, bool useXunitTime)
        {
            TimeSpan? testTime = useXunitTime ? (TimeSpan?)TimeSpan.FromSeconds(result.ExecutionTime) : null;

            if (!string.IsNullOrEmpty(result.Output))
                testContext.LogWriter.ConsoleOutput.Write(result.Output);

            if (result is XunitPassedResult)
            {
                testContext.FinishStep(TestOutcome.Passed, testTime);
                return true;
            }

            XunitFailedResult failedResult = result as XunitFailedResult;
            if (failedResult != null)
            {
                // Report the failure exception.
                testContext.LogWriter.Failures.WriteException(
                    new ExceptionData(
                        failedResult.ExceptionType ?? "",
                        failedResult.Message ?? "",
                        failedResult.StackTrace ?? "",
                        ExceptionData.NoProperties,
                        null), "Exception");

                testContext.FinishStep(TestOutcome.Failed, testTime);
                return false;
            }

            XunitSkipResult skipResult = result as XunitSkipResult;
            if (skipResult != null)
            {
                testContext.LogWriter.Warnings.Write("The test was skipped.  Reason: {0}\n",
                    string.IsNullOrEmpty(skipResult.Reason) ? "<unspecified>" : skipResult.Reason);
                testContext.FinishStep(TestOutcome.Skipped, testTime);
                return true;
            }

            throw new NotSupportedException(String.Format("Unrecognized Xunit method result type: '{0}'.", result.GetType()));
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:40,代码来源:XunitTestController.cs

示例2: RunTestCommandAndFinishStep

        private static bool RunTestCommandAndFinishStep(ITestContext testContext, XunitTestClassCommand testClassCommand, XunitTestCommand testCommand)
        {
            try
            {
                testContext.LifecyclePhase = LifecyclePhases.Execute;

                XunitMethodResult result = testCommand.Execute(testClassCommand.ObjectUnderTest);
                return LogMethodResultAndFinishStep(testContext, result, false);
            }
            catch (Exception ex)
            {
                // Xunit probably shouldn't throw an exception in a test command.
                // But just in case...
                testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                testContext.FinishStep(TestOutcome.Failed, null);
                return false;
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:18,代码来源:XunitTestController.cs

示例3: FinishStepWithReportRunResult

            private void FinishStepWithReportRunResult(ITestContext testContext, ReportRunResult reportRunResult)
            {
                TestOutcome outcome = GetOutcomeFromReportRunResult(reportRunResult);
                testContext.FinishStep(outcome, null);

                // only update assembly status if more severe
                if (outcome.Status > assemblyTestOutcome.Status)
                    assemblyTestOutcome = outcome;
            }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:9,代码来源:MbUnit2TestController.cs

示例4: RunTestClassCommandAndFinishStep

        private static TestResult RunTestClassCommandAndFinishStep(ITestCommand testCommand, ITestContext testContext, XunitTestClassCommand testClassCommand)
        {
            try
            {
                bool passed = true;

                // Run ClassStart behavior, if applicable.
                testContext.LifecyclePhase = LifecyclePhases.SetUp;
                Exception ex = testClassCommand.ClassStart();

                // Run tests.
                if (ex == null)
                {
                    List<MethodInfo> testMethods = new List<MethodInfo>();
                    List<ITestCommand> testCommands = new List<ITestCommand>();

                    foreach (ITestCommand child in testCommand.Children)
                    {
                        XunitTest test = child.Test as XunitTest;

                        if (test != null)
                        {
                            testMethods.Add(test.MethodInfo.Target.Resolve(false));
                            testCommands.Add(child);
                        }
                    }

                    while (testMethods.Count != 0)
                    {
                        XunitMethodInfo[] xunitTestMethods = GenericCollectionUtils.ConvertAllToArray(
                            testMethods, x => XunitReflector.Wrap(x));

                        int nextTestIndex = testClassCommand.ChooseNextTest(xunitTestMethods);
                        ITestCommand nextTestCommand = testCommands[nextTestIndex];
                        MethodInfo nextTestMethodInfo = testMethods[nextTestIndex];

                        testMethods.RemoveAt(nextTestIndex);
                        testCommands.RemoveAt(nextTestIndex);

                        passed &= RunTestMethod(nextTestCommand, nextTestMethodInfo, testClassCommand,
                            testContext.TestStep);
                    }
                }

                // Run ClassFinish behavior, if applicable.
                testContext.LifecyclePhase = LifecyclePhases.TearDown;
                ex = testClassCommand.ClassFinish() ?? ex;

                if (ex != null)
                {
                    testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                    passed = false;
                }

                return testContext.FinishStep(passed ? TestOutcome.Passed : TestOutcome.Failed, null);
            }
            catch (Exception ex)
            {
                // Xunit probably shouldn't throw an exception in a test command.
                // But just in case...
                testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                return testContext.FinishStep(TestOutcome.Failed, null);
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:64,代码来源:XunitTestController.cs

示例5: SafeFinishStep

 private static TestResult SafeFinishStep(ITestContext testContext, TestOutcome outcome, TimeSpan duration)
 {
     testContext.BecomeMultiThreadAware();
     using (TestContextTrackerAccessor.Instance.EnterContext(testContext))
         return testContext.FinishStep(outcome, duration);
 }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:6,代码来源:MSTestRunner.cs


注:本文中的ITestContext.FinishStep方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。