示例#1
0
        /// <summary>
        /// Method that actually performs the work. Overridden
        /// in CompositeWorkItem to do setup, run all child
        /// items and then do teardown.
        /// </summary>
        protected override void PerformWork()
        {
            // Inititialize actions, setup and teardown
            // We can't do this in the constructor because
            // the context is not available at that point.
            InitializeSetUpAndTearDownCommands();

            if (!CheckForCancellation())
            {
                if (Test.RunState == RunState.Explicit && !_childFilter.IsExplicitMatch(Test))
                {
                    SkipFixture(ResultState.Explicit, GetSkipReason(), null);
                }
                else
                {
                    switch (Test.RunState)
                    {
                    default:
                    case RunState.Runnable:
                    case RunState.Explicit:
                        // Assume success, since the result will be inconclusive
                        // if there is no setup method to run or if the
                        // context initialization fails.
                        Result.SetResult(ResultState.Success);

                        CreateChildWorkItems();

                        if (_children.Count > 0)
                        {
                            PerformOneTimeSetUp();

                            if (!CheckForCancellation())
                            {
                                switch (Result.ResultState.Status)
                                {
                                case TestStatus.Passed:
                                    RunChildren();
                                    return;

                                // Just return: completion event will take care
                                // of TestFixtureTearDown when all tests are done.

                                case TestStatus.Skipped:
                                case TestStatus.Inconclusive:
                                case TestStatus.Failed:
                                    SkipChildren(_suite, Result.ResultState.WithSite(FailureSite.Parent), "OneTimeSetUp: " + Result.Message);
                                    break;
                                }
                            }

                            // Directly execute the OneTimeFixtureTearDown for tests that
                            // were skipped, failed or set to inconclusive in one time setup
                            // unless we are aborting.
                            if (Context.ExecutionStatus != TestExecutionStatus.AbortRequested)
                            {
                                PerformOneTimeTearDown();
                            }
                        }
                        break;

                    case RunState.Skipped:
                        SkipFixture(ResultState.Skipped, GetSkipReason(), null);
                        break;

                    case RunState.Ignored:
                        SkipFixture(ResultState.Ignored, GetSkipReason(), null);
                        break;

                    case RunState.NotRunnable:
                        SkipFixture(ResultState.NotRunnable, GetSkipReason(), GetProviderStackTrace());
                        break;
                    }
                }
            }

            // Fall through in case nothing was run.
            // Otherwise, this is done in the completion event.
            WorkItemComplete();
        }
 public DefaultTestWorkItem(TestMethod test, ITestFilter filter)
     : base(test, null)
 {
     _command = test.RunState == RunState.Runnable || test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)
         ? BuildTestCommand(test)
         : new SkipCommand(test);
 }
示例#3
0
 /// <summary>
 /// Construct a simple work item for a test.
 /// </summary>
 /// <param name="test">The test to be executed</param>
 /// <param name="filter">The filter used to select this test</param>
 public SimpleWorkItem(TestMethod test, ITestFilter filter) : base(test)
 {
     _command = test.RunState == RunState.Runnable || test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)
         ? CommandBuilder.MakeTestCommand(test)
         : CommandBuilder.MakeSkipCommand(test);
 }
示例#4
0
        public static TestCommand BuildTestCommand(TestMethod test, ITestFilter filter)
        {
            if (test.RunState != RunState.Runnable &&
                !(test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)))
            {
                return(new SkipCommand(test));
            }

            var testReturnsIEnumerator = test.Method.ReturnType.Type == typeof(IEnumerator);

            TestCommand command;

            if (!testReturnsIEnumerator)
            {
                command = new UnityTestMethodCommand(test);
            }
            else
            {
                command = new EnumerableTestMethodCommand(test);
            }

            command = new UnityLogCheckDelegatingCommand(command);
            foreach (var wrapper in test.Method.GetCustomAttributes <IWrapTestMethod>(true))
            {
                command = wrapper.Wrap(command);
                if (command == null)
                {
                    var message = String.Format("IWrapTestMethod implementation '{0}' returned null as command.",
                                                wrapper.GetType().FullName);
                    return(new FailCommand(test, ResultState.Failure, message));
                }

                if (testReturnsIEnumerator && !(command is IEnumerableTestMethodCommand))
                {
                    command = TryReplaceWithEnumerableCommand(command);
                    if (command != null)
                    {
                        continue;
                    }

                    var message = String.Format("'{0}' is not supported on {1} as it does not handle returning IEnumerator.",
                                                wrapper.GetType().FullName,
                                                GetTestBuilderName(test));
                    return(new FailCommand(test, ResultState.Failure, message));
                }
            }

            command = new UnityEngine.TestTools.TestActionCommand(command);
            command = new UnityEngine.TestTools.SetUpTearDownCommand(command);

            if (!testReturnsIEnumerator)
            {
                command = new ImmediateEnumerableCommand(command);
            }

            foreach (var wrapper in test.Method.GetCustomAttributes <IWrapSetUpTearDown>(true))
            {
                command = wrapper.Wrap(command);
                if (command == null)
                {
                    var message = String.Format("IWrapSetUpTearDown implementation '{0}' returned null as command.",
                                                wrapper.GetType().FullName);
                    return(new FailCommand(test, ResultState.Failure, message));
                }

                if (testReturnsIEnumerator && !(command is IEnumerableTestMethodCommand))
                {
                    command = TryReplaceWithEnumerableCommand(command);
                    if (command != null)
                    {
                        continue;
                    }

                    var message = String.Format("'{0}' is not supported on {1} as it does not handle returning IEnumerator.",
                                                wrapper.GetType().FullName,
                                                GetTestBuilderName(test));
                    return(new FailCommand(test, ResultState.Failure, message));
                }
            }

            command = new EnumerableSetUpTearDownCommand(command);
            command = new OuterUnityTestActionCommand(command);

            IApplyToContext[] changes = test.Method.GetCustomAttributes <IApplyToContext>(true);
            if (changes.Length > 0)
            {
                command = new EnumerableApplyChangesToContextCommand(command, changes);
            }

            return(command);
        }
示例#5
0
        protected override IEnumerable PerformWork()
        {
            InitializeSetUpAndTearDownCommands();

            if (UnityTestExecutionContext.CurrentContext != null && m_DontRunRestoringResult && EditModeTestCallbacks.RestoringTestContext != null)
            {
                EditModeTestCallbacks.RestoringTestContext();
            }

            if (!CheckForCancellation())
            {
                if (Test.RunState == RunState.Explicit && !_childFilter.IsExplicitMatch(Test))
                {
                    SkipFixture(ResultState.Explicit, GetSkipReason(), null);
                }
                else
                {
                    switch (Test.RunState)
                    {
                    default:
                    case RunState.Runnable:
                    case RunState.Explicit:
                        Result.SetResult(ResultState.Success);

                        CreateChildWorkItems();

                        if (Children.Count > 0)
                        {
                            if (!m_DontRunRestoringResult)
                            {
                                //This is needed to give the editor a chance to go out of playmode if needed before creating objects.
                                //If we do not, the objects could be automatically destroyed when exiting playmode and could result in errors later on
                                yield return(null);

                                PerformOneTimeSetUp();
                            }

                            if (!CheckForCancellation())
                            {
                                switch (Result.ResultState.Status)
                                {
                                case TestStatus.Passed:
                                    foreach (var child in RunChildren())
                                    {
                                        if (CheckForCancellation())
                                        {
                                            yield break;
                                        }

                                        yield return(child);
                                    }
                                    break;

                                case TestStatus.Skipped:
                                case TestStatus.Inconclusive:
                                case TestStatus.Failed:
                                    SkipChildren(_suite, Result.ResultState.WithSite(FailureSite.Parent), "OneTimeSetUp: " + Result.Message);
                                    break;
                                }
                            }

                            if (Context.ExecutionStatus != TestExecutionStatus.AbortRequested && !m_DontRunRestoringResult)
                            {
                                PerformOneTimeTearDown();
                            }
                        }
                        break;

                    case RunState.Skipped:
                        SkipFixture(ResultState.Skipped, GetSkipReason(), null);
                        break;

                    case RunState.Ignored:
                        SkipFixture(ResultState.Ignored, GetSkipReason(), null);
                        break;

                    case RunState.NotRunnable:
                        SkipFixture(ResultState.NotRunnable, GetSkipReason(), GetProviderStackTrace());
                        break;
                    }
                }
            }
            if (!ResultedInDomainReload)
            {
                WorkItemComplete();
            }
        }
示例#6
0
 public bool IsExplicitMatch(nui.ITest test) => _filter.IsExplicitMatch(new TestWrapper(test));
 public CoroutineTestWorkItem(TestMethod test, ITestFilter filter)
     : base(test, null)
 {
     m_Command = test.RunState == RunState.Runnable || test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)
         ? CommandBuilder.MakeTestCommand(test)
         : CommandBuilder.MakeSkipCommand(test);
 }
示例#8
0
 /// <summary>
 /// Construct a simple work item for a test.
 /// </summary>
 /// <param name="test">The test to be executed</param>
 /// <param name="filter">The filter used to select this test</param>
 public SimpleWorkItem(TestMethod test, ITestFilter filter) : base(test) 
 {
     _command = test.RunState == RunState.Runnable || test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)
         ? CommandBuilder.MakeTestCommand(test)
         : CommandBuilder.MakeSkipCommand(test);
 }