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


C# TestExecutionContext类代码示例

本文整理汇总了C#中TestExecutionContext的典型用法代码示例。如果您正苦于以下问题:C# TestExecutionContext类的具体用法?C# TestExecutionContext怎么用?C# TestExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Execute

        /// <summary>
        /// Runs the test, saving a TestResult in the supplied TestExecutionContext.
        /// </summary>
        /// <param name="context">The context in which the test should run.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            try
            {
                for (int i = _setUpTearDownItems.Count; i > 0;)
                    _setUpTearDownItems[--i].RunSetUp(context);

                context.CurrentResult = innerCommand.Execute(context);
            }
            catch (Exception ex)
            {
#if !PORTABLE
                if (ex is ThreadAbortException)
                    Thread.ResetAbort();
#endif
                context.CurrentResult.RecordException(ex);
            }
            finally
            {
                if (context.ExecutionStatus != TestExecutionStatus.AbortRequested)
                {
                    for(int i = 0; i < _setUpTearDownItems.Count; i++)
                        _setUpTearDownItems[i].RunTearDown(context);
                }
            }

            return context.CurrentResult;
        }
开发者ID:textmetal,项目名称:main,代码行数:33,代码来源:SetUpTearDownCommand.cs

示例2: WorkItem

 /// <summary>
 /// Construct a WorkItem for a particular test.
 /// </summary>
 /// <param name="test">The test that the WorkItem will run</param>
 /// <param name="context">The TestExecutionContext in which it will run</param>
 public WorkItem(Test test, TestExecutionContext context)
 {
     _test = test;
     _testResult = test.MakeTestResult();
     _state = WorkItemState.Ready;
     _context = context;
 }
开发者ID:haf,项目名称:nunit-framework,代码行数:12,代码来源:WorkItem.cs

示例3: Execute

        /// <summary>
        /// Overridden to call the inner command and adjust the result
        /// in case all chlid results were inconclusive.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async override Task<TestResult> Execute(TestExecutionContext context)
        {
            TestResult theoryResult = await innerCommand.Execute(context);

            if (theoryResult.ResultState == ResultState.Success)
            {
                if (!theoryResult.HasChildren)
                    theoryResult.SetResult(ResultState.Failure, "No test cases were provided", null);
                else
                {
                    bool wasInconclusive = true;
                    foreach (TestResult childResult in theoryResult.Children)
                        if (childResult.ResultState == ResultState.Success)
                        {
                            wasInconclusive = false;
                            break;
                        }

                    if (wasInconclusive)
                        theoryResult.SetResult(ResultState.Failure, "All test cases were inconclusive", null);
                }
            }

            return theoryResult;
        }
开发者ID:kentcb,项目名称:nunitlite,代码行数:31,代码来源:TheoryResultCommand.cs

示例4: Execute

        /// <summary>
        /// Runs the test, saving a TestResult in the supplied TestExecutionContext
        /// </summary>
        /// <param name="context">The context in which the test should run.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            // TODO: This command duplicates the calculation of the
            // duration of the test because that calculation is 
            // normally performed at a higher level. Most likely,
            // we should move the maxtime calculation to the
            // higher level eventually.
#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !NETCF_2_0
            long startTicks = Stopwatch.GetTimestamp();
#endif

            TestResult testResult = innerCommand.Execute(context);

#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !NETCF_2_0
            long tickCount = Stopwatch.GetTimestamp() - startTicks;
            double seconds = (double)tickCount / Stopwatch.Frequency;
            testResult.Duration = TimeSpan.FromSeconds(seconds);
#else
            testResult.Duration = DateTime.Now - context.StartTime;
#endif

            if (testResult.ResultState == ResultState.Success)
            {
                //int elapsedTime = (int)Math.Round(testResult.Time * 1000.0);
                double elapsedTime = testResult.Duration.TotalMilliseconds;

                if (elapsedTime > maxTime)
                    testResult.SetResult(ResultState.Failure,
                        string.Format("Elapsed time of {0}ms exceeds maximum of {1}ms",
                            elapsedTime, maxTime));
            }

            return testResult;
        }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:39,代码来源:MaxTimeCommand.cs

示例5: Execute

        /// <summary>
        /// Runs the test, saving a TestResult in the supplied TestExecutionContext
        /// </summary>
        /// <param name="context">The context in which the test should run.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            // TODO: This command duplicates the calculation of the
            // duration of the test because that calculation is 
            // normally performed at a higher level. Most likely,
            // we should move the maxtime calculation to the
            // higher level eventually.
            long startTicks = Stopwatch.GetTimestamp();

            TestResult testResult = innerCommand.Execute(context);

            long tickCount = Stopwatch.GetTimestamp() - startTicks;
            double seconds = (double)tickCount / Stopwatch.Frequency;
            testResult.Duration = seconds;

            if (testResult.ResultState == ResultState.Success)
            {
                double elapsedTime = testResult.Duration * 1000d;

                if (elapsedTime > maxTime)
                    testResult.SetResult(ResultState.Failure,
                        string.Format("Elapsed time of {0}ms exceeds maximum of {1}ms",
                            elapsedTime, maxTime));
            }

            return testResult;
        }
开发者ID:alfeg,项目名称:nunit,代码行数:32,代码来源:MaxTimeCommand.cs

示例6: RunSetUp

        /// <summary>
        /// Run SetUp on this level.
        /// </summary>
        /// <param name="context">The execution context to use for running.</param>
        public void RunSetUp(TestExecutionContext context)
        {
            _setUpWasRun = true;

            foreach (MethodInfo setUpMethod in _setUpMethods)
                RunSetUpOrTearDownMethod(context, setUpMethod);
        }
开发者ID:alfeg,项目名称:nunit,代码行数:11,代码来源:SetUpTearDownItem.cs

示例7: Execute

        /// <summary>
        /// Overridden to run the teardown methods specified on the test.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            TestResult suiteResult = context.CurrentResult;

            if (fixtureType != null)
            {
                try
                {
                    int index = suite.oneTimeTearDownMethods.Length;
                    while (--index >= 0)
                    {
                        // TODO: Pass methods to constructor?
                        MethodInfo fixtureTearDown = suite.oneTimeTearDownMethods[index];
                        if (!fixtureTearDown.IsStatic && context.TestObject == null)
                            Console.WriteLine("Null TestObject in fixture teardown for " + Test.FullName);
                        Reflect.InvokeMethod(fixtureTearDown, fixtureTearDown.IsStatic ? null : context.TestObject);
                    }

                    IDisposable disposable = context.TestObject as IDisposable;
                    if (disposable != null)
                        disposable.Dispose();
                }
                catch (Exception ex)
                {
                    suiteResult.RecordTearDownException(ex);
                }
            }

            return suiteResult;
        }
开发者ID:haf,项目名称:nunit-framework,代码行数:35,代码来源:OneTimeTearDownCommand.cs

示例8: Execute

        /// <summary>
        /// Overridden to run the teardown methods specified on the test.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            TestResult suiteResult = context.CurrentResult;

            try
            {
                for (int i = _actions.Count; i > 0; )
                    _actions[--i].AfterTest(Test);

                if (_setUpTearDownItems != null)
                    foreach(var item in _setUpTearDownItems)
                        item.RunTearDown(context);

                IDisposable disposable = context.TestObject as IDisposable;
                if (disposable != null && Test is IDisposableFixture)
                    disposable.Dispose();

                //Clear references to test objects to reduce memory usage
                context.TestObject = null;
                Test.Fixture = null;
            }
            catch (Exception ex)
            {
                suiteResult.RecordTearDownException(ex);
            }

            return suiteResult;
        }
开发者ID:elv1s42,项目名称:nunit,代码行数:33,代码来源:OneTimeTearDownCommand.cs

示例9: Execute

        /// <summary>
        /// Overridden to run the one-time setup for a suite.
        /// </summary>
        /// <param name="context">The TestExecutionContext to be used.</param>
        /// <returns>A TestResult</returns>
        public override TestResult Execute(TestExecutionContext context)
        {
            if (_fixtureType != null)
            {
                // Use pre-constructed fixture if available, otherwise construct it
                if (!IsStaticClass(_fixtureType))
                {
                    context.TestObject = _suite.Fixture ?? Reflect.Construct(_fixtureType, _arguments);
                    if (_suite.Fixture == null)
                    {
                        _suite.Fixture = context.TestObject;
                    }
                    Test.Fixture = _suite.Fixture;
                }

                for (int i = _setUpTearDown.Count; i > 0; )
                    _setUpTearDown[--i].RunSetUp(context);
            }


            for (int i = 0; i < _actions.Count; i++)
                _actions[i].BeforeTest(Test);

            return context.CurrentResult;
        }
开发者ID:JohanLarsson,项目名称:nunit,代码行数:30,代码来源:OneTimeSetUpCommand.cs

示例10: CreateWorkItem

 public static WorkItem CreateWorkItem(Test test, TestExecutionContext context, ITestFilter filter)
 {
     TestSuite suite = test as TestSuite;
     if (suite != null && (suite.RunState == RunState.Runnable || suite.RunState == RunState.Explicit))
         return new CompositeWorkItem(suite, context, filter);
     else
         return new SimpleWorkItem(test, context);
 }
开发者ID:pjcollins,项目名称:Andr.Unit,代码行数:8,代码来源:WorkItem.cs

示例11: CreateWorkItem

 static public WorkItem CreateWorkItem(Test test, TestExecutionContext context, ITestFilter filter)
 {
     TestSuite suite = test as TestSuite;
     if (suite != null)
         return new CompositeWorkItem(suite, context, filter);
     else
         return new SimpleWorkItem((TestMethod)test, context);
 }
开发者ID:haf,项目名称:nunit-framework,代码行数:8,代码来源:WorkItem.cs

示例12: WorkItem

 /// <summary>
 /// Construct a WorkItem for a particular test.
 /// </summary>
 /// <param name="test">The test that the WorkItem will run</param>
 /// <param name="context">The context to be used for running this test</param>
 public WorkItem(Test test, TestExecutionContext context)
 {
     _test = test;
     _context = context.Save();
     testResult = test.MakeTestResult();
     _command = test.GetTestCommand();
     _state = WorkItemState.Ready;
 }
开发者ID:pjcollins,项目名称:Andr.Unit,代码行数:13,代码来源:WorkItem.cs

示例13: CompositeWorkItem

 /// <summary>
 /// Construct a CompositeWorkItem for executing a test suite
 /// using a filter to select child tests.
 /// </summary>
 /// <param name="suite">The TestSuite to be executed</param>
 /// <param name="context">The execution context to be used</param>
 /// <param name="childFilter">A filter used to select child tests</param>
 public CompositeWorkItem(TestSuite suite, TestExecutionContext context, ITestFilter childFilter)
     : base(suite, context)
 {
     _suite = suite;
     _setupCommand = suite.GetOneTimeSetUpCommand();
     _teardownCommand = suite.GetOneTimeTearDownCommand();
     _childFilter = childFilter;
 }
开发者ID:haf,项目名称:nunit-framework,代码行数:15,代码来源:CompositeWorkItem.cs

示例14: RunTestMethod

        private async Task<object> RunTestMethod(TestExecutionContext context)
        {
#if NET_4_5
            if (MethodHelper.IsAsyncMethod(testMethod.Method))
                return await RunAsyncTestMethod(context);
            else
#endif
                return RunNonAsyncTestMethod(context);
        }
开发者ID:kentcb,项目名称:nunitlite,代码行数:9,代码来源:TestMethodCommand.cs

示例15: RunTestMethod

        private object RunTestMethod(TestExecutionContext context)
        {
#if NET_4_0 || NET_4_5
            if (AsyncInvocationRegion.IsAsyncOperation(testMethod.Method))
                return RunAsyncTestMethod(context);
            else
#endif
                return RunNonAsyncTestMethod(context);
        }
开发者ID:balaghanta,项目名称:nunit-framework,代码行数:9,代码来源:TestMethodCommand.cs


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