示例#1
0
        /// <summary>
        /// Overridden to check for invalid combinations of settings
        /// </summary>
        /// <param name="test"></param>
        public override void ApplyToTest(Test test)
        {
            // Adjust property to include ParallelScope.Self if a fixture has ParallelScope.Fixtures on it
            if (test is TestFixture && _scope.HasFlag(ParallelScope.Fixtures))
            {
                Properties.Set(PropertyNames.ParallelScope, _scope | ParallelScope.Self);
            }

            base.ApplyToTest(test);

            if (test.RunState == RunState.NotRunnable)
            {
                return;
            }

            if (_scope.HasFlag(ParallelScope.Self) && _scope.HasFlag(ParallelScope.None))
            {
                test.MakeInvalid("Test may not be both parallel and non-parallel");
            }

            if (test is TestMethod && _scope.HasFlag(ParallelScope.ContextMask))
            {
                test.MakeInvalid("ParallelScope of a test method may not specify Children or Fixtures");
            }
        }
示例#2
0
        /// <summary>
        /// Overridden to check for invalid combinations of settings
        /// </summary>
        /// <param name="test"></param>
        public override void ApplyToTest(Test test)
        {
            base.ApplyToTest(test);

            if (test.RunState == RunState.NotRunnable)
            {
                return;
            }

            if (_scope.HasFlag(ParallelScope.Self) && _scope.HasFlag(ParallelScope.None))
            {
                test.MakeInvalid("Test may not be both parallel and non-parallel");
            }

            if (test is TestMethod && _scope.HasFlag(ParallelScope.ContextMask))
            {
                test.MakeInvalid("ParallelScope of a test method may not specify Children or Fixtures");
            }
        }
示例#3
0
        private ParallelExecutionStrategy GetExecutionStrategy()
        {
            // If there is no fixture and so nothing to do but dispatch
            // grandchildren we run directly. This saves time that would
            // otherwise be spent enqueuing and dequeing items.
            if (Test.TypeInfo == null)
            {
                return(ParallelExecutionStrategy.Direct);
            }

            // If the context is single-threaded we are required to run
            // the tests one by one on the same thread as the fixture.
            if (Context.IsSingleThreaded)
            {
                return(ParallelExecutionStrategy.Direct);
            }

            // Check if item is explicitly marked as non-parallel
            if (ParallelScope.HasFlag(ParallelScope.None))
            {
                return(ParallelExecutionStrategy.NonParallel);
            }

            // Check if item is explicitly marked as parallel
            if (ParallelScope.HasFlag(ParallelScope.Self))
            {
                return(ParallelExecutionStrategy.Parallel);
            }

            // Item is not explicitly marked, so check the inherited context
            if (Context.ParallelScope.HasFlag(ParallelScope.Children) ||
                Test is TestFixture && Context.ParallelScope.HasFlag(ParallelScope.Fixtures))
            {
                return(ParallelExecutionStrategy.Parallel);
            }

            // There is no scope specified either on the item itself or in the context.
            // In that case, simple work items are test cases and just run on the same
            // thread, while composite work items and teardowns are non-parallel.
            return(this is SimpleWorkItem
                ? ParallelExecutionStrategy.Direct
                : ParallelExecutionStrategy.NonParallel);
        }