Exemplo n.º 1
0
        /// <summary>
        ///     Run selected tests synchronously or asynchronously, notifying the listener interface as it progresses.
        /// </summary>
        /// <param name="assemblies">The list of test assembly runners to run.</param>
        /// <param name="listener">Interface to receive EventListener notifications.</param>
        /// <param name="filter">A test filter used to select tests to be run.</param>
        /// <param name="runAsync"><c>true</c> to run tests asynchronously, otherwise <c>false</c> to run synchronously.</param>
        /// <param name="results">The <see cref="ITestResult" /> object to add the test results to.</param>
        private static void RunTests(IList <ITestAssemblyRunner> assemblies,
                                     ITestListener listener, ITestFilter filter, bool runAsync, ref TestSuiteResult results)
        {
            filter = ValidateFilter(filter);
            Queue <ITestAssemblyRunner> testQueue = new Queue <ITestAssemblyRunner>(assemblies);

            // Check each test not ran when first encountered to see if it is ready to be run
            while (testQueue.Count > 0)
            {
                // Run test if not currently running, otherwise queue up to be checked again later
                ITestAssemblyRunner test = testQueue.Dequeue();
                if (!test.IsTestRunning)
                {
                    if (runAsync)
                    {
                        test.RunAsync(listener, filter);
                    }
                    else
                    {
                        test.Run(listener, filter);
                    }
                }
                else
                {
                    // Test not ready to run so re-enqueue
                    testQueue.Enqueue(test);
                }

                // Slow down the polling loop to give time for tests to complete
                if (runAsync)
                {
                    Thread.Sleep(10);
                }
            }

            // Wait for tests to complete
            while (assemblies.Any(test => test.IsTestRunning || !test.IsTestComplete))
            // Slow down the polling loop to give time for tests to complete
            {
                Thread.Sleep(10);
            }

            // Add individual test runner results to overall result
            foreach (ITestAssemblyRunner test in assemblies)
            {
                if (test.Result != null)
                {
                    results.AddResult(test.Result);
                }
            }
        }
        public void RunAsync_AfterLoad_ReturnsRunnableSuite()
        {
            LoadMockAssembly();
            _runner.RunAsync(TestListener.NULL, TestFilter.Empty);
            _runner.WaitForCompletion(Timeout.Infinite);

            Assert.NotNull(_runner.Result, "No result returned");
            Assert.That(_runner.Result.Test.IsSuite);
            Assert.That(_runner.Result.Test, Is.TypeOf <TestAssembly>());
            Assert.That(_runner.Result.Test.RunState, Is.EqualTo(RunState.Runnable));
            Assert.That(_runner.Result.Test.TestCaseCount, Is.EqualTo(MockAssembly.Tests));
            Assert.That(_runner.Result.ResultState, Is.EqualTo(ResultState.ChildFailure));
            Assert.That(_runner.Result.PassCount, Is.EqualTo(MockAssembly.Success));
            Assert.That(_runner.Result.FailCount, Is.EqualTo(MockAssembly.ErrorsAndFailures));
            Assert.That(_runner.Result.SkipCount, Is.EqualTo(MockAssembly.Skipped));
            Assert.That(_runner.Result.InconclusiveCount, Is.EqualTo(MockAssembly.Inconclusive));
        }
 /// <inheritdoc />
 public void RunAsync(ITestListener listener, ITestFilter filter)
 {
     v_IsTestCompleteOverride = false;
     v_IsTestRunningOverride  = false;
     v_Runner.RunAsync(listener, filter);
 }