Beispiel #1
0
        public async Task <TestResultCollection> Run(ITestCategory category,
                                                     CancellationToken cancellationToken)
        {
            TestResultCollection result;

            var runners = GetTestRunners(category);

            if (runners.Count == 1)
            {
                result = await Run(category, runners [0], cancellationToken);

                AddWarnings(result);
                return(result);
            }

            result = new TestResultCollection(Name);

            for (int i = 0; i < runners.Count; i++)
            {
                var runner = runners [i];
                result.AddChild(await Run(category, runner, cancellationToken));
            }

            AddWarnings(result);
            return(result);
        }
Beispiel #2
0
        IList <ITestRunner> GetTestRunners(ITestCategory category)
        {
            var list = new List <ITestRunner> ();

            if (disabled)
            {
                return(list.AsReadOnly());
            }

            foreach (var runner in Framework.GetTestRunners(this))
            {
                if (!category.IsEnabled(runner))
                {
                    continue;
                }
                if (!HasCustomThreadingMode())
                {
                    list.Add(runner);
                    continue;
                }
                if (HasDefaultThreadingMode())
                {
                    list.Add(new ThreadingModeProxyRunner(runner, ThreadingMode.Default));
                }
                CheckThreadingModeProxy(list, runner, ThreadingMode.MainThread);
                CheckThreadingModeProxy(list, runner, ThreadingMode.ExitContext);
                CheckThreadingModeProxy(list, runner, ThreadingMode.ThreadPool);
            }
            return(list.AsReadOnly());
        }
Beispiel #3
0
 internal static bool Filter(TestCase test, ITestRunner runner, ITestCategory category)
 {
     if (!test.IsEnabled || !category.IsEnabled(test) || !runner.IsEnabled(test))
     {
         return(false);
     }
     if (test.Categories.Where(c => !c.Equals(category)).Any(c => c.Explicit))
     {
         return(false);
     }
     return(filters.Where(f => !f.Equals(category)).All(f => f.Filter(test)));
 }
Beispiel #4
0
        public async Task <TestResultCollection> Run(ITestCategory category, int repeatCount,
                                                     CancellationToken cancellationToken)
        {
            var result = new TestResultCollection(Name);

            try {
                for (int i = 0; i < hosts.Length; i++)
                {
                    await hosts[i].SetUp(this);
                }
            } catch (Exception ex) {
                Log("SetUp failed: {0}", ex);
                result.AddChild(new TestError(Name, "SetUp failed", ex));
                return(result);
            }

            if (repeatCount == 1)
            {
                CurrentIteration = MaxIterations = 1;
                await DoRun(category, result, cancellationToken);
            }
            else
            {
                MaxIterations = repeatCount;
                for (CurrentIteration = 0; CurrentIteration < repeatCount; CurrentIteration++)
                {
                    var name      = string.Format("{0} (iteration {1})", Name, CurrentIteration + 1);
                    var iteration = new TestResultCollection(name);
                    result.AddChild(iteration);
                    await DoRun(category, iteration, cancellationToken);
                }
            }

            try {
                for (int i = 0; i < hosts.Length; i++)
                {
                    await hosts[i].TearDown(this);
                }
            } catch (Exception ex) {
                Log("TearDown failed: {0}", ex);
                result.AddChild(new TestError(Name, "TearDown failed", ex));
            }

            OnStatusMessageEvent("Test suite finished.");

            return(result);
        }
Beispiel #5
0
 async Task DoRun(ITestCategory category, TestResultCollection result,
                  CancellationToken cancellationToken)
 {
     foreach (var fixture in fixtures)
     {
         if (!fixture.IsEnabled(category))
         {
             continue;
         }
         try {
             result.AddChild(await fixture.Run(category, cancellationToken));
         } catch (Exception ex) {
             Log("Test fixture {0} failed: {1}", fixture.Name, ex);
             result.AddChild(new TestError(fixture.Name, "Test fixture failed", ex));
         }
     }
 }
Beispiel #6
0
        async Task <TestResultCollection> Run(ITestCategory category, ITestRunner runner,
                                              CancellationToken cancellationToken)
        {
            string name = Name;

            if (runner.Name != null)
            {
                name = string.Format("{0} ({1})", Name, runner.Name);
            }

            var result = new TestResultCollection(name);

            var selected = Tests.Where(test => TestSuite.Filter(test, runner, category));

            if (Attribute.ReuseContext)
            {
                await Run(runner, result, selected, cancellationToken);

                return(result);
            }

            foreach (var test in selected)
            {
                var array = new TestCase[] { test };

                bool reuseContext = GetReuseContext(test);
                int  repeat       = reuseContext ? 1 : GetRepeat(test);

                for (int i = 0; i < repeat; i++)
                {
                    await Run(runner, result, array, cancellationToken);
                }
            }

            return(result);
        }
Beispiel #7
0
 public bool IsEnabled(ITestCategory category)
 {
     return(!disabled && GetTestRunners(category).Any(
                runner => tests.Any(test => TestSuite.Filter(test, runner, category))));
 }
		async Task<TestResultCollection> Run (ITestCategory category, ITestRunner runner,
		                                      CancellationToken cancellationToken)
		{
			string name = Name;
			if (runner.Name != null)
				name = string.Format ("{0} ({1})", Name, runner.Name);

			var result = new TestResultCollection (name);

			var selected = Tests.Where (test => TestSuite.Filter (test, runner, category));

			if (Attribute.ReuseContext) {
				await Run (runner, result, selected, cancellationToken);
				return result;
			}

			foreach (var test in selected) {
				var array = new TestCase[] { test };

				bool reuseContext = GetReuseContext (test);
				int repeat = reuseContext ? 1 : GetRepeat (test);

				for (int i = 0; i < repeat; i++)
					await Run (runner, result, array, cancellationToken);
			}

			return result;
		}
		public async Task<TestResultCollection> Run (ITestCategory category,
		                                             CancellationToken cancellationToken)
		{
			TestResultCollection result;

			var runners = GetTestRunners (category);
			if (runners.Count == 1) {
				result = await Run (category, runners [0], cancellationToken);
				AddWarnings (result);
				return result;
			}

			result = new TestResultCollection (Name);

			for (int i = 0; i < runners.Count; i++) {
				var runner = runners [i];
				result.AddChild (await Run (category, runner, cancellationToken));
			}

			AddWarnings (result);
			return result;
		}
Beispiel #10
0
		public bool IsEnabled (ITestCategory category)
		{
			return !disabled && GetTestRunners (category).Any (
				runner => tests.Any (test => TestSuite.Filter (test, runner, category)));
		}
Beispiel #11
0
		IList<ITestRunner> GetTestRunners (ITestCategory category)
		{
			var list = new List<ITestRunner> ();
			if (disabled)
				return list.AsReadOnly ();

			foreach (var runner in Framework.GetTestRunners (this)) {
				if (!category.IsEnabled (runner))
					continue;
				if (!HasCustomThreadingMode ()) {
					list.Add (runner);
					continue;
				}
				if (HasDefaultThreadingMode ())
					list.Add (new ThreadingModeProxyRunner (runner, ThreadingMode.Default));
				CheckThreadingModeProxy (list, runner, ThreadingMode.MainThread);
				CheckThreadingModeProxy (list, runner, ThreadingMode.ExitContext);
				CheckThreadingModeProxy (list, runner, ThreadingMode.ThreadPool);
			}
			return list.AsReadOnly ();
		}