public UnitTestResult RunTestSuite (XUnitAssemblyTestSuite rootSuite, XUnitTestSuite testSuite, TestContext context)
		{
			var testCases = new List<XUnitTestCase> ();
			CollectTestCases (testCases, testSuite);

			return Run (testCases, rootSuite, testSuite, context);
		}
		public UnitTestResult RunAssemblyTestSuite (XUnitAssemblyTestSuite assemblyTestSuite, TestContext context)
		{
			var testCases = new List<XUnitTestCase> ();

			foreach (var test in assemblyTestSuite.Tests) {
				var testSuite = test as XUnitTestSuite;
				if (testSuite != null)
					CollectTestCases (testCases, testSuite);
			}

			return Run (testCases, assemblyTestSuite, assemblyTestSuite, context);
		}
		public void Begin (TestContext context)
		{
			if (!isActive) {
				this.context = context;

				// notify the parent session before starting the test itself
				if (parentSession != null)
					parentSession.OnChildSessionStarting (this, context);

				if (reportToMonitor) {
					context.Monitor.BeginTest (unitTest);
					unitTest.Status = TestStatus.Running;
				}

				isActive = true;
			}
		}
		UnitTestResult Run (List<XUnitTestCase> testCases, XUnitAssemblyTestSuite rootSuite, IExecutableTest test, TestContext context, bool reportToMonitor = true)
		{
			using (var session = test.CreateExecutionSession (reportToMonitor)) {
				var executionListener = new RemoteExecutionListener (new LocalExecutionListener (context, testCases));
				RemotingServices.Marshal (executionListener, null, typeof (IXUnitExecutionListener));

				XUnitTestRunner runner = (XUnitTestRunner)Runtime.ProcessService.CreateExternalProcessObject (typeof(XUnitTestRunner),
					context.ExecutionContext, rootSuite.SupportAssemblies);

				try {
					runner.Execute (rootSuite.AssemblyPath, testCases.Select (tc => tc.TestInfo).ToArray (), executionListener);
				} finally {
					runner.Dispose ();
				}

				return session.Result;
			}
		}
		public UnitTestResult RunTestCase (XUnitAssemblyTestSuite rootSuite, XUnitTestCase testCase, TestContext context)
		{
			return Run (new List<XUnitTestCase> { testCase }, rootSuite, testCase, context, false);
		}
		protected virtual UnitTestResult OnRunChildTest (UnitTest test, TestContext testContext)
		{
			return test.Run (testContext);
		}
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			UnitTestResult tres = new UnitTestResult ();
			OnBeginTest (testContext);
			
			try {
				foreach (UnitTest t in Tests) {
					UnitTestResult res;
					try {
						res = OnRunChildTest (t, testContext);
						if (testContext.Monitor.IsCancelRequested)
							break;
					} catch (Exception ex) {
						res = UnitTestResult.CreateFailure (ex);
					}
					tres.Time += res.Time;
					tres.Status |= res.Status;
					tres.TotalFailures += res.TotalFailures;
					tres.TotalSuccess += res.TotalSuccess;
					tres.TotalIgnored += res.TotalIgnored;
				}
			} finally {
				OnEndTest (testContext);
			}
			return tres;
		}
		public void RegisterResult (TestContext context, UnitTestResult result)
		{
			// Avoid registering results twice
			if (lastResult != null && lastResult.TestDate == context.TestDate)
				return;

			result.TestDate = context.TestDate;
//			if ((int)result.Status == 0)
//				result.Status = ResultStatus.Ignored;
			lastResult = result;
			IResultsStore store = GetResultsStore ();
			if (store != null)
				store.RegisterResult (ActiveConfiguration, this, result);
			OnTestStatusChanged ();
		}
		public UnitTestResult Run (TestContext testContext)
		{
			testContext.Monitor.BeginTest (this);
			UnitTestResult res = null;
			object ctx = testContext.ContextData;
			
			try {
				Status = TestStatus.Running;
				res = OnRun (testContext);
			} catch (global::NUnit.Framework.SuccessException) {
				res = UnitTestResult.CreateSuccess();
			} catch (global::NUnit.Framework.IgnoreException ex) {
				res = UnitTestResult.CreateIgnored(ex.Message);
			} catch (global::NUnit.Framework.InconclusiveException ex) {
				res = UnitTestResult.CreateInconclusive(ex.Message);
			} catch (Exception ex) {
				res = UnitTestResult.CreateFailure (ex);
			} finally {
				Status = TestStatus.Ready;
				testContext.Monitor.EndTest (this, res);
			}
			RegisterResult (testContext, res);
			testContext.ContextData = ctx;
			return res;
		}
Beispiel #10
0
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			UnitTestResult tres = new UnitTestResult ();
			OnBeginTest (testContext);
			
			try {
				foreach (UnitTest t in Tests) {
					if (t.IsExplicit)
						continue;
					UnitTestResult res;
					try {
						res = OnRunChildTest (t, testContext);
						if (testContext.Monitor.IsCancelRequested)
							break;
					} catch (Exception ex) {
						res = UnitTestResult.CreateFailure (ex);
					}
					tres.Add (res);
				}
			} finally {
				OnEndTest (testContext);
			}
			return tres;
		}
		public void OnPassed (TestContext context, string id, decimal executionTime, string output)
		{
			var result = session.Result;
			VirtualTest test = null;

			int count = CountResults (session.Result);

			if (count > 0) {
				if (count < 2) {
					test = new VirtualTest (this, count);
					result = CopyResult (session.Result);

					session.Context.Monitor.BeginTest (test);
					session.Context.Monitor.EndTest (test, result);
					test.RegisterResult (session.Context, result);

					session.Result.Add (result);
					count++;
				}

				test = new VirtualTest (this, count);
				result = new UnitTestResult ();
			}

			result.Status = ResultStatus.Success;
			result.Passed = 1;

			result.Time = TimeSpan.FromSeconds (Decimal.ToDouble (executionTime));
			result.ConsoleOutput = output;

			if (test != null) {
				session.Context.Monitor.BeginTest (test);
				session.Context.Monitor.EndTest (test, result);
				test.RegisterResult (session.Context, result);

				session.Result.Add (result);
			}
		}
		void RunTests ()
		{
			try {
				NUnitService.ResetResult (test);

				TestContext ctx = new TestContext (monitor, resultsPad, context, DateTime.Now);
				test.Run (ctx);
				test.SaveResults ();
			} catch (Exception ex) {
				LoggingService.LogError (ex.ToString ());
				monitor.ReportRuntimeError (null, ex);
			} finally {
				monitor.FinishTestRun ();
			}
		}
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			return executor.RunAssemblyTestSuite (this, testContext);
		}
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			return rootSuite.RunUnitTest (this, fullName, fullName, null, testContext);
		}
		public void OnSkipped (TestContext context, string id, string reason)
		{
			var result = session.Result;
			VirtualTest test = null;

			int count = CountResults (session.Result);

			if (count > 0) {
				if (count < 2) {
					test = new VirtualTest (this, count);
					result = CopyResult (session.Result);

					session.Context.Monitor.BeginTest (test);
					session.Context.Monitor.EndTest (test, result);
					test.RegisterResult (session.Context, result);

					session.Result.Add (result);
					count++;
				}

				test = new VirtualTest (this, count);
				result = new UnitTestResult ();
			}

			result.Status = ResultStatus.Ignored;
			result.Ignored = 1;

			if (reason != null)
				result.Message = reason;

			if (test != null) {
				session.Context.Monitor.BeginTest (test);
				session.Context.Monitor.EndTest (test, result);
				test.RegisterResult (session.Context, result);

				session.Result.Add (result);
			}
		}
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			TestRunnerType = (string) project.ExtendedProperties ["TestRunnerType"];
			var asm = project.ExtendedProperties ["TestRunnerAssembly"];
			TestRunnerAssembly = asm != null ? project.BaseDirectory.Combine (asm.ToString ()).ToString () : null;
			return base.OnRun (testContext);
		}
			protected override UnitTestResult OnRun (TestContext testContext)
			{
				return null;
			}
		void OnChildSessionStarting (XUnitExecutionSession childSession, TestContext context)
		{
			// begin session if the first child session started
			if (++childSessionsStarted == 1)
				Begin (context);
		}
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			return executor.RunTestCase (rootSuite, this, testContext);
		}
Beispiel #20
0
		public UnitTestResult Run (TestContext testContext)
		{
			testContext.Monitor.BeginTest (this);
			UnitTestResult res = null;
			object ctx = testContext.ContextData;
			
			try {
				Status = TestStatus.Running;
				res = OnRun (testContext);
			} catch (Exception ex) {
				res = UnitTestResult.CreateFailure (ex);
			} finally {
				Status = TestStatus.Ready;
				testContext.Monitor.EndTest (this, res);
			}
			RegisterResult (testContext, res);
			testContext.ContextData = ctx;
			return res;
		}
		public void OnStarting (TestContext context, string id)
		{
			session.Begin (context);
		}
		protected abstract UnitTestResult OnRun (TestContext testContext);
		public void OnFinished (TestContext context, string id)
		{
			session.End ();
		}
Beispiel #24
0
		void RunTests ()
		{
			try {
				NUnitService.ResetResult (test);

				TestContext ctx = new TestContext (monitor, resultsPad, context, DateTime.Now);
				test.Run (ctx);
				test.SaveResults ();
				success = true;
			} catch (Exception ex) {
				LoggingService.LogError (ex.ToString ());
				monitor.ReportRuntimeError (null, ex);
				success = false;
			} finally {
				monitor.FinishTestRun ();
				runThread = null;
			}
			lock (this) {
				if (waitEvent != null)
					waitEvent.Set ();
			}
			if (Completed != null)
				Completed (this);
		}
		public void OnFailed (TestContext context, string id, decimal executionTime, string output, string[] exceptionTypes, string[] messages, string[] stackTraces)
		{
			UnitTestResult result = session.Result;
			VirtualTest test = null;

			int count = CountResults (session.Result);

			if (count > 0) {
				if (count < 2) {
					test = new VirtualTest (this, count);
					result = CopyResult (session.Result);

					session.Context.Monitor.BeginTest (test);
					session.Context.Monitor.EndTest (test, result);
					test.RegisterResult (session.Context, result);

					session.Result.Add (result);
					count++;
				}

				test = new VirtualTest (this, count);
				result = new UnitTestResult ();
			}

			result.Status = ResultStatus.Failure;
			result.Failures = 1;

			result.Time = TimeSpan.FromSeconds (Decimal.ToDouble (executionTime));
			result.ConsoleOutput = output;

			if (messages.Length > 0)
				result.Message = messages [0];

			if (stackTraces.Length > 0)
				result.StackTrace = stackTraces [0];

			if (test != null) {
				session.Context.Monitor.BeginTest (test);
				session.Context.Monitor.EndTest (test, result);
				test.RegisterResult (session.Context, result);

				session.Result.Add (result);
			}
		}
		protected virtual void OnBeginTest (TestContext testContext)
		{
		}
		protected override UnitTestResult OnRun (TestContext testContext)
		{
			return rootSuite.RunUnitTest (this, className, pathName, Name, testContext);
		}
		protected virtual void OnEndTest (TestContext testContext)
		{
		}
		public LocalExecutionListener (TestContext context, List<XUnitTestCase> testCases)
		{
			this.context = context;

			// create a lookup table so later we can identify a test case by it's id
			lookup = testCases.ToDictionary (tc => tc.TestInfo.Id);
		}