Пример #1
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);
        }
        /// <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));
        }
Пример #3
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)
            {
                results.Add(task.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();

            TestEngineResult result = ResultHelper.Merge(results);

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