Example #1
0
        protected override async Task <ITestResult> RunInternalAsync(ITestFilter filter)
        {
            var results = new MultipleTestResult(_testSuite);

            _testFilter    = filter;
            _runnersToTest = new Queue <ITestRunner>(Runners.Where(r => _testFilter.Pass((r.TestSuite))));

            OnTestStarted(new UnitTestTestEventArgs(_testSuite));
            try
            {
                while (_runnersToTest.Count > 0)
                {
                    lock (this)
                    {
                        _currentRunner               = _runnersToTest.Dequeue();
                        _currentRunner.Log          += currentRunner_Log;
                        _currentRunner.Progress     += currentRunner_Progress;
                        _currentRunner.TestStarted  += currentRunner_TestStarted;
                        _currentRunner.TestFinished += currentRunner_TestFinished;
                    }
                    var result = await _currentRunner.RunAsync(filter);

                    results.Results.Add(result);

                    _currentRunner.Log          -= currentRunner_Log;
                    _currentRunner.Progress     -= currentRunner_Progress;
                    _currentRunner.TestStarted  -= currentRunner_TestStarted;
                    _currentRunner.TestFinished -= currentRunner_TestFinished;
                }
                OnTestFinished(new UnitTestResultEventArgs(results));
            }
            finally
            {
                _currentRunner = null;
            }
            return(results);
        }
Example #2
0
		async void RunTests(CategoryFilter filter = null)
		{
			if (!startButton.Enabled)
				return;
			startButton.Enabled = false;
			var keywords = search.Text;
			Log.Write(null, "Starting tests...");
			var testPlatform = useTestPlatform.Checked == true ? new TestPlatform() : Platform;
			try
			{
				await Task.Run(() =>
				{
					using (Platform.ThreadStart())
					{
						try
						{
							var listener = new TestListener { Application = Application.Instance }; // use running application for logging

							var builder = new DefaultTestAssemblyBuilder();
							var runner = new NUnitTestAssemblyRunner(builder);
							var settings = new Dictionary<string, object>();
							var result = new MultipleTestResult();
							if (filter != null)
								filter.SkipCount = 0;
							foreach (var assembly in ((TestApplication)TestApplication.Instance).TestAssemblies)
							{
								runner.Load(assembly, settings);

								filter = filter ?? new CategoryFilter();
								filter.Application = Application.Instance;
								filter.ExecutingAssembly = assembly;
								if (testPlatform is TestPlatform)
									filter.IncludeCategories.Add(UnitTests.TestUtils.TestPlatformCategory);
								else
									filter.IncludeCategories.RemoveAll(r => r == UnitTests.TestUtils.TestPlatformCategory);
								filter.Keyword = keywords;
								using (testPlatform.Context)
								{
									result.Results.Add(runner.Run(listener, filter));
								}
							}
							var writer = new StringWriter();
							writer.WriteLine(result.FailCount > 0 ? "FAILED" : "PASSED");
							writer.WriteLine("\tPass: {0}, Fail: {1}, Skipped: {2}, Inconclusive: {3}", result.PassCount, result.FailCount, result.SkipCount + filter.SkipCount, result.InconclusiveCount);
							writer.Write("\tDuration: {0}", result.Duration);
							Application.Instance.Invoke(() => Log.Write(null, writer.ToString()));
						}
						catch (Exception ex)
						{
							Application.Instance.Invoke(() => Log.Write(null, "Error running tests: {0}", ex));
						}
						finally
						{
							Application.Instance.Invoke(() => startButton.Enabled = true);
						}
					}
				});
			}
			catch (Exception ex)
			{
				Log.Write(null, "Error running tests\n{0}", ex);
			}
		}
Example #3
0
        async void RunTests(CategoryFilter filter = null)
        {
            if (!startButton.Enabled)
            {
                return;
            }
            startButton.Enabled = false;
            var keywords = search.Text;

            Log.Write(null, "Starting tests...");
            var testPlatform   = useTestPlatform.Checked == true ? new TestPlatform() : Platform;
            var runManualTests = includeManualTests.Checked == true;

            try
            {
                await Task.Run(() =>
                {
                    using (Platform.ThreadStart())
                    {
                        try
                        {
                            var listener = new TestListener {
                                Application = Application.Instance
                            };                                                                                                  // use running application for logging

                            var builder  = new DefaultTestAssemblyBuilder();
                            var runner   = new NUnitTestAssemblyRunner(builder);
                            var settings = new Dictionary <string, object>();
                            var result   = new MultipleTestResult();
                            if (filter != null)
                            {
                                filter.SkipCount = 0;
                            }
                            foreach (var assembly in ((TestApplication)TestApplication.Instance).TestAssemblies)
                            {
                                runner.Load(assembly, settings);

                                filter                   = filter ?? new CategoryFilter();
                                filter.Application       = Application.Instance;
                                filter.ExecutingAssembly = assembly;
                                if (!runManualTests)
                                {
                                    filter.ExcludeCategories.Add(UnitTests.TestBase.ManualTestCategory);
                                }
                                if (testPlatform is TestPlatform)
                                {
                                    filter.IncludeCategories.Add(UnitTests.TestBase.TestPlatformCategory);
                                }
                                else
                                {
                                    filter.IncludeCategories.RemoveAll(r => r == UnitTests.TestBase.TestPlatformCategory);
                                }
                                filter.Keyword = keywords;
                                using (testPlatform.Context)
                                {
                                    result.Results.Add(runner.Run(listener, filter));
                                }
                            }
                            var writer = new StringWriter();
                            writer.WriteLine(result.FailCount > 0 ? "FAILED" : "PASSED");
                            writer.WriteLine("\tPass: {0}, Fail: {1}, Skipped: {2}, Inconclusive: {3}", result.PassCount, result.FailCount, result.SkipCount + filter.SkipCount, result.InconclusiveCount);
                            writer.Write("\tDuration: {0}", result.Duration);
                            Application.Instance.Invoke(() => Log.Write(null, writer.ToString()));
                        }
                        catch (Exception ex)
                        {
                            Application.Instance.Invoke(() => Log.Write(null, "Error running tests: {0}", ex));
                        }
                        finally
                        {
                            Application.Instance.Invoke(() => startButton.Enabled = true);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                Log.Write(null, "Error running tests\n{0}", ex);
            }
        }