コード例 #1
0
 private void RunTestsSequentially(ITestEventListener listener, TestFilter filter, List <TestEngineResult> results, bool disposeRunners)
 {
     foreach (ITestEngineRunner runner in Runners)
     {
         var task = new TestExecutionTask(runner, listener, filter, disposeRunners);
         task.Execute();
         LogResultsFromTask(task, results, _unloadExceptions);
     }
 }
コード例 #2
0
        private static void LogResultsFromTask(TestExecutionTask task, List<TestEngineResult> results, List<Exception> unloadExceptions)
        {
            var result = task.Result;
            if (result != null)
            {
                results.Add(result);
            }

            if (task.UnloadException != null)
            {
                unloadExceptions.Add(task.UnloadException);
            }
        }
コード例 #3
0
        /// <summary>
        /// Run the tests in a loaded TestPackage
        /// </summary>
        /// <param name="listener">An ITestEventHandler to receive events</param>
        /// <param name="filter">A TestFilter used to select tests</param>
        /// <returns>
        /// A TestEngineResult giving the result of the test execution.
        /// </returns>
        protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter)
        {
            var results = new List <TestEngineResult>();

            bool disposeRunners = TestPackage.GetSetting(PackageSettings.DisposeRunners, false);

            int levelOfParallelism = GetLevelOfParallelism();

            if (levelOfParallelism <= 1 || _runners.Count <= 1)
            {
                foreach (ITestEngineRunner runner in _runners)
                {
                    results.Add(runner.Run(listener, filter));
                    if (disposeRunners)
                    {
                        runner.Dispose();
                    }
                }
            }
            else
            {
                var workerPool = new ParallelTaskWorkerPool(levelOfParallelism);
                var tasks      = new List <TestExecutionTask>();

                foreach (ITestEngineRunner runner in _runners)
                {
                    var task = new TestExecutionTask(runner, listener, filter, disposeRunners);
                    tasks.Add(task);
                    workerPool.Enqueue(task);
                }

                workerPool.Start();
                workerPool.WaitAll();

                foreach (var task in tasks)
                {
                    results.Add(task.Result());
                }
            }

            if (disposeRunners)
            {
                _runners.Clear();
            }

            TestEngineResult result = ResultHelper.Merge(results);

            return(IsProjectPackage(TestPackage)
                ? result.MakePackageResult(TestPackage.Name, TestPackage.FullName)
                : result);
        }
コード例 #4
0
        /// <summary>
        /// Run the tests in a loaded TestPackage
        /// </summary>
        /// <param name="listener">An ITestEventHandler to receive events</param>
        /// <param name="filter">A TestFilter used to select tests</param>
        /// <returns>
        /// A TestEngineResult giving the result of the test execution.
        /// </returns>
        protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter)
        {
            var results = new List <TestEngineResult>();

            bool disposeRunners = TestPackage.GetSetting(EnginePackageSettings.DisposeRunners, false);

            if (LevelOfParallelism <= 1)
            {
                foreach (ITestEngineRunner runner in Runners)
                {
                    results.Add(runner.Run(listener, filter));
                    if (disposeRunners)
                    {
                        runner.Dispose();
                    }
                }
            }
            else
            {
                var workerPool = new ParallelTaskWorkerPool(LevelOfParallelism);
                var tasks      = new List <TestExecutionTask>();

                foreach (ITestEngineRunner runner in Runners)
                {
                    var task = new TestExecutionTask(runner, listener, filter, disposeRunners);
                    tasks.Add(task);
                    workerPool.Enqueue(task);
                }

                workerPool.Start();
                workerPool.WaitAll();

                foreach (var task in tasks)
                {
                    results.Add(task.Result());
                }
            }

            if (disposeRunners)
            {
                Runners.Clear();
            }

            return(ResultHelper.Merge(results));
        }
コード例 #5
0
        private void RunTestsInParallel(ITestEventListener listener, TestFilter filter, List<TestEngineResult> results, bool disposeRunners)
        {
            var workerPool = new ParallelTaskWorkerPool(LevelOfParallelism);
            var tasks = new List<TestExecutionTask>();

            foreach (ITestEngineRunner runner in Runners)
            {
                var task = new TestExecutionTask(runner, listener, filter, disposeRunners);
                tasks.Add(task);
                workerPool.Enqueue(task);
            }

            workerPool.Start();
            workerPool.WaitAll();

            foreach (var task in tasks)
                LogResultsFromTask(task, results, _unloadExceptions);
        }
コード例 #6
0
        /// <summary>
        /// Run the tests in a loaded TestPackage
        /// </summary>
        /// <param name="listener">An ITestEventHandler to receive events</param>
        /// <param name="filter">A TestFilter used to select tests</param>
        /// <returns>
        /// A TestEngineResult giving the result of the test execution.
        /// </returns>
        protected override TestEngineResult RunTests(ITestEventListener listener, TestFilter filter)
        {
            var results = new List<TestEngineResult>();

            bool disposeRunners = TestPackage.GetSetting(EnginePackageSettings.DisposeRunners, false);

            if (LevelOfParallelism <= 1)
            {
                foreach (ITestEngineRunner runner in _runners)
                {
                    results.Add(runner.Run(listener, filter));
                    if (disposeRunners) runner.Dispose();
                }
            }
            else
            {
                var workerPool = new ParallelTaskWorkerPool(LevelOfParallelism);
                var tasks = new List<TestExecutionTask>();

                foreach (ITestEngineRunner runner in _runners)
                {
                    var task = new TestExecutionTask(runner, listener, filter, disposeRunners);
                    tasks.Add(task);
                    workerPool.Enqueue(task);
                }

                workerPool.Start();
                workerPool.WaitAll();

                foreach (var task in tasks)
                    results.Add(task.Result());
            }

            if (disposeRunners) _runners.Clear();

            TestEngineResult result = ResultHelper.Merge(results);

            return IsProjectPackage(TestPackage)
                ? result.MakePackageResult(TestPackage.Name, TestPackage.FullName)
                : result;
        }