public XUnitExecutionSession (UnitTest unitTest, bool reportToMonitor)
		{
			this.reportToMonitor = reportToMonitor;
			this.unitTest = unitTest;
			result = new UnitTestResult ();
			childSessions = new List<XUnitExecutionSession> ();
		}
		public void RegisterResult (string configuration, UnitTest test, UnitTestResult result)
		{
			string aname = test.StoreRelativeName;
			
			TestRecord root = GetRootRecord (configuration, result.TestDate);
			if (root == null) {
				root = new TestRecord ();
				fileCache [GetRootFileName (configuration, result.TestDate)] = root;
			}
			root.Modified = true;
			TestRecord record = root;
			
			if (aname.Length > 0) {
				string[] path = test.StoreRelativeName.Split ('.');
				foreach (string p in path) {
					TestRecord ctr = record.Tests != null ? record.Tests [p] : null;
					if (ctr == null) {
						ctr = new TestRecord ();
						ctr.Name = p;
						if (record.Tests == null)
							record.Tests = new TestRecordCollection ();
						record.Tests.Add (ctr);
					}
					record = ctr;
				}
			}
			
			if (record.Results == null)
				record.Results = new UnitTestResultCollection ();
			record.Results.Add (result);
		}
		public static UnitTestResult CreateInconclusive (string message)
		{
			UnitTestResult res = new UnitTestResult ();
			res.status = ResultStatus.Inconclusive;
			res.Message = message;
			return res;
		}
		public static UnitTestResult CreateIgnored (string message)
		{
			UnitTestResult res = new UnitTestResult ();
			res.status = ResultStatus.Ignored;
			res.Message = message;
			return res;
		}
		public static UnitTestResult CreateFailure (string message, Exception ex)
		{
			UnitTestResult res = new UnitTestResult ();
			res.status = ResultStatus.Failure;
			res.Message = message;
			res.stackTrace = ex.Message + "\n" + ex.StackTrace;
			return res;
		}
		public void EndTest (UnitTest test, UnitTestResult result)
		{
			Runtime.RunInMainThread (delegate {
				monitor.EndTest (test, result);
			});
		}
Пример #7
0
		public void EndTest (UnitTest test, UnitTestResult result) {
			monitor.EndTest (test, result);
		}
Пример #8
0
		public void ResetLastResult ()
		{
			lastResult = null;
			OnTestStatusChanged ();
		}
		UnitTestResult ReportXmlResult (IRemoteEventListener listener, XElement elem, string testPrefix, bool macunitStyle)
		{
			UnitTestResult result = new UnitTestResult ();
			var time = (string)elem.Attribute ("time");
			if (time != null)
				result.Time = TimeSpan.FromSeconds (double.Parse (time, CultureInfo.InvariantCulture));
			result.TestDate = DateTime.Now;

			var reason = elem.Element ("reason");
			if (reason != null)
				result.Message = (string) reason;

			var failure = elem.Element ("failure");
			if (failure != null) {
				var msg = failure.Element ("message");
				if (msg != null)
					result.Message = (string)msg;
				var stack = failure.Element ("stack-trace");
				if (stack != null)
					result.StackTrace = (string)stack;
			}

			switch ((string)elem.Attribute ("result")) {
			case "Error":
			case "Failure":
				result.Status = ResultStatus.Failure;
				break;
			case "Success":
				result.Status = ResultStatus.Success;
				break;
			case "Ignored":
				result.Status = ResultStatus.Ignored;
				break;
			default:
				result.Status = ResultStatus.Inconclusive;
				break;
			}

			if (elem.Name == "test-suite") {
				// nunitlite does not emit <test-suite type="Namespace" elements so we need to fake
				// them by deconstructing the full type name and emitting the suite started events manually
				var names = new List<string> ();
				if (!macunitStyle || (string)elem.Attribute ("type") == "Assembly")
					names.Add ("<root>");
				else
					names.AddRange (elem.Attribute ("name").Value.Split ('.'));

				for (int i = 0; i < names.Count; i ++)
					listener.SuiteStarted (testPrefix + string.Join (".", names.Take (i + 1)));

				var name = (string)elem.Attribute ("type") == "Assembly" ? "<root>" : (string) elem.Attribute ("name");
				var cts = elem.Element ("results");
				if (cts != null) {
					foreach (var ct in cts.Elements ()) {
						var r = ReportXmlResult (listener, ct, name != "<root>" ? testPrefix + name + "." : "", macunitStyle);
						result.Add (r);
					}
				}
				for (int i = 0; i < names.Count; i ++)
					listener.SuiteFinished (testPrefix + string.Join (".", names.Take (i + 1)), result);
			} else {
				string name = (string)elem.Attribute ("name");
				switch (result.Status) {
				case ResultStatus.Success:
					result.Passed++;
					break;
				case ResultStatus.Failure:
					result.Failures++;
					break;
				case ResultStatus.Ignored:
					result.Ignored++;
					break;
				case ResultStatus.Inconclusive:
					result.Inconclusive++;
					break;
				}

				listener.TestStarted (name);
				listener.TestFinished (name, result);
			}
			return result;
		}
Пример #10
0
		void ShowTestResult (UnitTest test, UnitTestResult result)
		{
			if (result.IsSuccess) {
				if (!buttonSuccess.Active)
					return;
				TreeIter testRow = failuresStore.AppendValues (TestStatusIcon.Success, Escape (test.FullName), test);
				failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
			}
			if (result.IsFailure) {
				if (!buttonFailures.Active)
					return;
				string file = test.SourceCodeLocation != null ? test.SourceCodeLocation.FileName + ":" + test.SourceCodeLocation.Line : null;
				TreeIter testRow = failuresStore.AppendValues (TestStatusIcon.Failure, Escape (test.FullName), test, file);
				bool hasMessage = result.Message != null && result.Message.Length > 0;
				if (hasMessage)
					failuresStore.AppendValues (testRow, null, Escape (result.Message), test);
				if (result.StackTrace != null && result.StackTrace.Length > 0) {
					TreeIter row = testRow;
					if (hasMessage)
						row = failuresStore.AppendValues (testRow, null, GettextCatalog.GetString ("Stack Trace"), test);
					AddStackTrace (row, result.StackTrace, test);
				}
				failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
			}
			if (result.IsNotRun) {
				if (!buttonIgnored.Active)
					return;
				TreeIter testRow = failuresStore.AppendValues (TestStatusIcon.NotRun, Escape (test.FullName), test);
				if (result.Message != null)
					failuresStore.AppendValues (testRow, null, Escape (result.Message), test);
				failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
			}
			if (result.IsInconclusive) {
				if (!buttonInconclusive.Active)
					return;
				TreeIter testRow = failuresStore.AppendValues (TestStatusIcon.Inconclusive, Escape (test.FullName), test);
				if (result.Message != null)
					failuresStore.AppendValues (testRow, null, Escape (result.Message), test);
				failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
			}
			
			string msg = GettextCatalog.GetString ("Running {0} ...", test.FullName);
			TextIter it = outputView.Buffer.EndIter;
			outIters [test] = it.Offset;
			outputView.Buffer.InsertWithTags (ref it, msg, bold);
			outputView.Buffer.Insert (ref it, "\n");
			if (result.ConsoleOutput != null)
				outputView.Buffer.Insert (ref it, result.ConsoleOutput);
			if (result.ConsoleError != null)
				outputView.Buffer.Insert (ref it, result.ConsoleError);
			outputView.ScrollMarkOnscreen (outputView.Buffer.InsertMark);
		}
Пример #11
0
		UnitTestResult CopyResult (UnitTestResult origin)
		{
			var result = new UnitTestResult ();

			result.Status = origin.Status;
			result.Time = origin.Time;
			result.ConsoleOutput = origin.ConsoleOutput;
			result.Message = origin.Message;
			result.StackTrace = origin.StackTrace;

			result.Passed = session.Result.Passed;
			result.Errors = session.Result.Errors;
			result.Failures = session.Result.Failures;
			result.Ignored = session.Result.Ignored;
			result.Inconclusive = session.Result.Inconclusive;
			result.Skipped = session.Result.Skipped;

			return result;
		}
Пример #12
0
		int CountResults (UnitTestResult result)
		{
			int count = 0;
			count += result.Passed;
			count += result.Errors;
			count += result.Failures;
			count += result.Ignored;
			count += result.Inconclusive;
			count += result.Skipped;
			return count;
		}
Пример #13
0
		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);
			}
		}
Пример #14
0
 public void EndTest(UnitTest test, UnitTestResult result)
 {
     DispatchService.GuiDispatch(delegate {
         monitor.EndTest(test, result);
     });
 }
Пример #15
0
        void ShowTestResult(UnitTest test, UnitTestResult result)
        {
            if (result.IsSuccess)
            {
                if (!buttonSuccess.Active)
                {
                    return;
                }
                TreeIter testRow = failuresStore.AppendValues(TestStatusIcon.Success, Escape(test.FullName), test);
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }
            if (result.IsFailure)
            {
                if (!buttonFailures.Active)
                {
                    return;
                }
                string   file       = test.SourceCodeLocation != null ? test.SourceCodeLocation.FileName + ":" + test.SourceCodeLocation.Line : null;
                TreeIter testRow    = failuresStore.AppendValues(TestStatusIcon.Failure, Escape(test.FullName), test, file);
                bool     hasMessage = !string.IsNullOrEmpty(result.Message);

                if (hasMessage)
                {
                    failuresStore.AppendValues(testRow, null, "<span font='" + FontService.MonospaceFontName + "'>" + Escape(result.Message) + "</span>", test, null, 0, ErrorMessage);
                }
                if (!string.IsNullOrEmpty(result.StackTrace))
                {
                    TreeIter row = testRow;
                    if (hasMessage)
                    {
                        row = failuresStore.AppendValues(testRow, null, GettextCatalog.GetString("Stack Trace"), test, null, 0, StackTrace);
                    }
                    AddStackTrace(row, result.StackTrace, test);
                }
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }
            if (result.IsNotRun)
            {
                if (!buttonIgnored.Active)
                {
                    return;
                }
                TreeIter testRow = failuresStore.AppendValues(TestStatusIcon.NotRun, Escape(test.FullName), test);
                if (result.Message != null)
                {
                    failuresStore.AppendValues(testRow, null, Escape(result.Message), test);
                }
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }
            if (result.IsInconclusive)
            {
                if (!buttonInconclusive.Active)
                {
                    return;
                }
                TreeIter testRow = failuresStore.AppendValues(TestStatusIcon.Inconclusive, Escape(test.FullName), test);
                if (result.Message != null)
                {
                    failuresStore.AppendValues(testRow, null, Escape(result.Message), test);
                }
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }

            string   msg = GettextCatalog.GetString("Running {0} ...", test.FullName);
            TextIter it  = outputView.Buffer.EndIter;

            outIters [test] = it.Offset;
            outputView.Buffer.InsertWithTags(ref it, msg, bold);
            outputView.Buffer.Insert(ref it, "\n");
            if (result.ConsoleOutput != null)
            {
                outputView.Buffer.Insert(ref it, result.ConsoleOutput);
            }
            if (result.ConsoleError != null)
            {
                outputView.Buffer.Insert(ref it, result.ConsoleError);
            }
            outputView.ScrollMarkOnscreen(outputView.Buffer.InsertMark);
        }
Пример #16
0
        void IPadContent.Initialize(IPadWindow window)
        {
            this.window = window;

            DockItemToolbar toolbar = window.GetToolbar(PositionType.Top);

            buttonSuccess        = new ToggleButton();
            buttonSuccess.Label  = GettextCatalog.GetString("Successful Tests");
            buttonSuccess.Active = false;
            buttonSuccess.Image  = new ImageView(TestStatusIcon.Success);
            buttonSuccess.Image.Show();
            buttonSuccess.Toggled    += new EventHandler(OnShowSuccessfulToggled);
            buttonSuccess.TooltipText = GettextCatalog.GetString("Show Successful Tests");
            toolbar.Add(buttonSuccess);

            buttonInconclusive        = new ToggleButton();
            buttonInconclusive.Label  = GettextCatalog.GetString("Inconclusive Tests");
            buttonInconclusive.Active = true;
            buttonInconclusive.Image  = new ImageView(TestStatusIcon.Inconclusive);
            buttonInconclusive.Image.Show();
            buttonInconclusive.Toggled    += new EventHandler(OnShowInconclusiveToggled);
            buttonInconclusive.TooltipText = GettextCatalog.GetString("Show Inconclusive Tests");
            toolbar.Add(buttonInconclusive);

            buttonFailures        = new ToggleButton();
            buttonFailures.Label  = GettextCatalog.GetString("Failed Tests");
            buttonFailures.Active = true;
            buttonFailures.Image  = new ImageView(TestStatusIcon.Failure);
            buttonFailures.Image.Show();
            buttonFailures.Toggled    += new EventHandler(OnShowFailuresToggled);
            buttonFailures.TooltipText = GettextCatalog.GetString("Show Failed Tests");
            toolbar.Add(buttonFailures);

            buttonIgnored        = new ToggleButton();
            buttonIgnored.Label  = GettextCatalog.GetString("Ignored Tests");
            buttonIgnored.Active = true;
            buttonIgnored.Image  = new ImageView(TestStatusIcon.NotRun);
            buttonIgnored.Image.Show();
            buttonIgnored.Toggled    += new EventHandler(OnShowIgnoredToggled);
            buttonIgnored.TooltipText = GettextCatalog.GetString("Show Ignored Tests");
            toolbar.Add(buttonIgnored);

            buttonOutput        = new ToggleButton();
            buttonOutput.Label  = GettextCatalog.GetString("Output");
            buttonOutput.Active = false;
            buttonOutput.Image  = ImageService.GetImage(MonoDevelop.Ide.Gui.Stock.OutputIcon, IconSize.Menu);
            buttonOutput.Image.Show();
            buttonOutput.Toggled    += new EventHandler(OnShowOutputToggled);
            buttonOutput.TooltipText = GettextCatalog.GetString("Show Output");
            toolbar.Add(buttonOutput);

            toolbar.Add(new SeparatorToolItem());

            buttonRun       = new Button();
            buttonRun.Label = GettextCatalog.GetString("Rerun Tests");
            buttonRun.Image = new ImageView(ImageService.GetIcon("nunit-run", IconSize.Menu));
            buttonRun.Image.Show();
            buttonRun.Sensitive = false;
            toolbar.Add(buttonRun);

            buttonStop = new Button(new Gtk.Image(Ide.Gui.Stock.Stop, Gtk.IconSize.Menu));
            toolbar.Add(buttonStop);
            toolbar.ShowAll();

            buttonStop.Clicked += new EventHandler(OnStopClicked);
            buttonRun.Clicked  += new EventHandler(OnRunClicked);

            // Run panel

            DockItemToolbar runPanel = window.GetToolbar(PositionType.Bottom);

            infoSep = new VSeparator();

            resultLabel.UseMarkup    = true;
            infoCurrent.Ellipsize    = Pango.EllipsizeMode.Start;
            infoCurrent.WidthRequest = 0;
            runPanel.Add(resultLabel);
            runPanel.Add(progressBar);
            runPanel.Add(infoCurrent, true, 10);

            labels = new HBox(false, 10);

            infoLabel.UseMarkup = true;

            labels.PackStart(infoLabel, true, false, 0);

            runPanel.Add(new Gtk.Label(), true);
            runPanel.Add(labels);
            runPanel.Add(infoSep, false, 10);

            progressBar.HeightRequest = infoLabel.SizeRequest().Height;
            runPanel.ShowAll();
            progressBar.Hide();
            infoSep.Hide();
            resultSummary = new UnitTestResult();
            UpdateCounters();
        }
Пример #17
0
 public void ResetLastResult()
 {
     lastResult = null;
     OnTestStatusChanged();
 }
 void ShowTestResult(UnitTest test, UnitTestResult result)
 {
     if (result.IsSuccess) {
         if (!buttonSuccess.Active)
             return;
         TreeIter testRow = failuresStore.AppendValues (CircleImage.Success, Escape (test.FullName), test);
         failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
     }
     if (result.IsFailure) {
         if (!buttonFailures.Active)
             return;
         TreeIter testRow = failuresStore.AppendValues (CircleImage.Failure, Escape (test.FullName), test);
         bool hasMessage = result.Message != null && result.Message.Length > 0;
         if (hasMessage)
             failuresStore.AppendValues (testRow, null, Escape (result.Message), test);
         if (result.StackTrace != null && result.StackTrace.Length > 0) {
             TreeIter row = testRow;
             if (hasMessage)
                 row = failuresStore.AppendValues (testRow, null, "Stack Trace", test);
             failuresStore.AppendValues (row, null, Escape (result.StackTrace), test);
         }
         failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
     }
     if (result.IsIgnored) {
         if (!buttonIgnored.Active)
             return;
         TreeIter testRow = failuresStore.AppendValues (CircleImage.NotRun, Escape (test.FullName), test);
         failuresStore.AppendValues (testRow, null, Escape (result.Message), test);
         failuresTreeView.ScrollToCell (failuresStore.GetPath (testRow), null, false, 0, 0);
     }
     if (result.ConsoleOutput != null)
         outputView.Buffer.InsertAtCursor (result.ConsoleOutput);
     if (result.ConsoleError != null)
         outputView.Buffer.InsertAtCursor (result.ConsoleError);
     outputView.ScrollMarkOnscreen (outputView.Buffer.InsertMark);
 }
Пример #19
0
		public void OnTestSuiteChanged (object sender, EventArgs e)
		{
			if (failuresTreeView.IsRealized)
				failuresTreeView.ScrollToPoint (0, 0);

			results.Clear ();
			
			error = null;
			errorMessage = null;
			
			failuresStore.Clear ();
			outputView.Buffer.Clear ();
			outIters.Clear ();
			progressBar.Fraction = 0;
			progressBar.Text = "";
			testsRun = 0;
			resultSummary = new UnitTestResult ();
			UpdateCounters ();
			if (rootTest != null) {
				rootTest = testService.SearchTest (rootTest.FullName);
				if (rootTest == null)
					buttonRun.Sensitive = false;
			}
		}
Пример #20
0
		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);
			}
		}
Пример #21
0
		public void EndTest (UnitTest test, UnitTestResult result)
		{
			DispatchService.GuiDispatch (delegate {
				monitor.EndTest (test, result);
			});
		}
Пример #22
0
 public void Add(UnitTestResult test)
 {
     ((IList)this).Add(test);
 }
Пример #23
0
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var          outFile = Path.GetTempFileName();
            LocalConsole cons    = new LocalConsole();

            try {
                MonoDevelop.NUnit.External.TcpTestListener tcpListener = null;
                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

                bool automaticUpdates = cmd.Command != null && (cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests")));
                if (!string.IsNullOrEmpty(pathName))
                {
                    cmd.Arguments += " -run=" + test.TestId;
                }
                if (automaticUpdates)
                {
                    tcpListener    = new MonoDevelop.NUnit.External.TcpTestListener(localMonitor, suiteName);
                    cmd.Arguments += " -port=" + tcpListener.Port;
                }

                // Note that we always dispose the tcp listener as we don't want it listening
                // forever if the test runner does not try to connect to it
                using (tcpListener) {
                    var p = testContext.ExecutionContext.Execute(cmd, cons);

                    testContext.Monitor.CancelRequested += p.Cancel;
                    if (testContext.Monitor.IsCancelRequested)
                    {
                        p.Cancel();
                    }
                    p.WaitForCompleted();

                    if (new FileInfo(outFile).Length == 0)
                    {
                        throw new Exception("Command failed");
                    }
                }

                // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees
                // that if guiunit is being used then it will give us updates. If you have a regular test
                // assembly compiled against nunit.framework.dll
                if (automaticUpdates && tcpListener.HasReceivedConnection)
                {
                    if (testName != null)
                    {
                        return(localMonitor.SingleTestResult);
                    }
                    return(test.GetLastResult());
                }

                XDocument doc = XDocument.Load(outFile);

                if (doc.Root != null)
                {
                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        cons.SetDone();
                        var ot = cons.Out.ReadToEnd();
                        var et = cons.Error.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }

                        bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null;
                        var  result       = ReportXmlResult(localMonitor, root, "", macunitStyle);
                        if (testName != null)
                        {
                            result = localMonitor.SingleTestResult;
                        }
                        return(result);
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                cons.SetDone();
                var ot = cons.Out.ReadToEnd();
                var et = cons.Error.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
            }
        }
Пример #24
0
        public void Fill(UnitTest test)
        {
            serieFailed.Clear();
            serieSuccess.Clear();
            serieIgnored.Clear();
            serieTime.Clear();

            this.test = test;

            if (showLastTest)
            {
                if (timeScale)
                {
                    lastDateValue = DateTime.Now.Ticks;
                }
                else
                {
                    lastTestNumber = 0;
                }
            }

            UnitTestResult first = null;

            UnitTestResult[] results;
            UnitTestResult   lastResult = test.Results.GetLastResult(DateTime.Now);

            if (lastResult == null)
            {
                return;
            }

            if (timeScale)
            {
                DateTime startDate;
                if (showLastTest)
                {
                    startDate = lastResult.TestDate - currentSpan;
                    StartX    = startDate.Ticks;
                    EndX      = lastResult.TestDate.Ticks;
                    first     = test.Results.GetLastResult(startDate);
                    results   = test.Results.GetResults(startDate, lastResult.TestDate);
                }
                else
                {
                    DateTime endDate = new DateTime((long)lastDateValue);
                    startDate = endDate - currentSpan;
                    StartX    = (double)startDate.Ticks;
                    EndX      = (double)endDate.Ticks;
                    first     = test.Results.GetLastResult(startDate);
                    results   = test.Results.GetResults(startDate, lastResult.TestDate);
                }
                if (singleDayResult)
                {
                    first = test.Results.GetPreviousResult(new DateTime(startDate.Year, startDate.Month, startDate.Day));
                    ArrayList list = new ArrayList();
                    if (first != null)
                    {
                        list.Add(first);
                    }
                    for (int n = 0; n < results.Length - 1; n++)
                    {
                        DateTime d1 = results [n].TestDate;
                        DateTime d2 = results [n + 1].TestDate;
                        if (d1.Day != d2.Day || d1.Month != d2.Month || d1.Year != d2.Year)
                        {
                            list.Add(results [n]);
                        }
                    }
                    list.Add(results [results.Length - 1]);
                    results = (UnitTestResult[])list.ToArray(typeof(UnitTestResult));
                }

                if (resetCursors)
                {
                    SelectionEnd.Value = EndX;
                    if (results.Length > 1)
                    {
                        SelectionStart.Value = results [results.Length - 2].TestDate.Ticks;
                    }
                    else
                    {
                        SelectionStart.Value = EndX;
                    }
                    resetCursors = false;
                }
            }
            else
            {
                if (singleDayResult)
                {
                    ArrayList list = new ArrayList();
                    list.Add(lastResult);
                    while (list.Count < testCount + (int)lastTestNumber + 1)
                    {
                        UnitTestResult res = test.Results.GetPreviousResult(lastResult.TestDate);
                        if (res == null)
                        {
                            break;
                        }
                        if (res.TestDate.Day != lastResult.TestDate.Day || res.TestDate.Month != lastResult.TestDate.Month || res.TestDate.Year != lastResult.TestDate.Year)
                        {
                            list.Add(res);
                        }
                        lastResult = res;
                    }
                    results = (UnitTestResult[])list.ToArray(typeof(UnitTestResult));
                    Array.Reverse(results);
                }
                else
                {
                    results = test.Results.GetResultsToDate(DateTime.Now, testCount + (int)lastTestNumber + 1);
                }
                EndX   = lastTestNumber + testCount;
                StartX = lastTestNumber;

                if (resetCursors)
                {
                    SelectionStart.Value = StartX;
                    SelectionEnd.Value   = StartX + 1;
                    resetCursors         = false;
                }
            }


            currentResults = results;
            if (testRunAxis != null)
            {
                testRunAxis.CurrentResults = currentResults;
            }

            if (Type == TestChartType.Results)
            {
                if (first != null)
                {
                    double x = timeScale ? first.TestDate.Ticks : results.Length;
                    serieFailed.AddData(x, first.ErrorsAndFailures);
                    serieSuccess.AddData(x, first.Passed);
                    serieIgnored.AddData(x, first.TestsNotRun);
                }

                for (int n = 0; n < results.Length; n++)
                {
                    UnitTestResult res = results [n];
                    double         x   = timeScale ? res.TestDate.Ticks : results.Length - n - 1;
                    serieFailed.AddData(x, res.ErrorsAndFailures);
                    serieSuccess.AddData(x, res.Passed);
                    serieIgnored.AddData(x, res.TestsNotRun);
                }
            }
            else
            {
                if (first != null)
                {
                    double x = timeScale ? first.TestDate.Ticks : results.Length;
                    serieTime.AddData(x, first.Time.TotalMilliseconds);
                }
                for (int n = 0; n < results.Length; n++)
                {
                    UnitTestResult res = results [n];
                    double         x   = timeScale ? res.TestDate.Ticks : results.Length - n - 1;
                    serieTime.AddData(x, results [n].Time.TotalMilliseconds);
                }
            }
        }
Пример #25
0
 void ITestProgressMonitor.EndTest(UnitTest test, UnitTestResult result)
 {
     monitor.EndTest(test, result);
 }
Пример #26
0
        internal UnitTestResult RunUnitTest(UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var runnerExe = GetCustomConsoleRunnerCommand();

            if (runnerExe != null)
            {
                return(RunWithConsoleRunner(runnerExe, test, suiteName, pathName, testName, testContext));
            }

            ExternalTestRunner runner       = (ExternalTestRunner)Runtime.ProcessService.CreateExternalProcessObject(typeof(ExternalTestRunner), testContext.ExecutionContext, UserAssemblyPaths);
            LocalTestMonitor   localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

            ITestFilter filter = null;

            if (test != null)
            {
                if (test is UnitTestGroup)
                {
                    filter = new TestNameFilter(CollectTests((UnitTestGroup)test));
                }
                else
                {
                    filter = new TestNameFilter(test.TestId);
                }
            }
            else
            {
                NUnitCategoryOptions categoryOptions = (NUnitCategoryOptions)test.GetOptions(typeof(NUnitCategoryOptions));
                if (categoryOptions.EnableFilter && categoryOptions.Categories.Count > 0)
                {
                    string[] cats = new string [categoryOptions.Categories.Count];
                    categoryOptions.Categories.CopyTo(cats, 0);
                    filter = new CategoryFilter(cats);
                    if (categoryOptions.Exclude)
                    {
                        filter = new NotFilter(filter);
                    }
                }
            }

            RunData rd = new RunData();

            rd.Runner       = runner;
            rd.Test         = this;
            rd.LocalMonitor = localMonitor;
            testContext.Monitor.CancelRequested += new TestHandler(rd.Cancel);

            UnitTestResult result;

            try {
                if (string.IsNullOrEmpty(AssemblyPath))
                {
                    string msg = GettextCatalog.GetString("Could not get a valid path to the assembly. There may be a conflict in the project configurations.");
                    throw new Exception(msg);
                }
                System.Runtime.Remoting.RemotingServices.Marshal(localMonitor, null, typeof(IRemoteEventListener));

                string testRunnerAssembly, testRunnerType;
                GetCustomTestRunner(out testRunnerAssembly, out testRunnerType);

                result = runner.Run(localMonitor, filter, AssemblyPath, "", new List <string> (SupportAssemblies), testRunnerType, testRunnerAssembly);
                if (testName != null)
                {
                    result = localMonitor.SingleTestResult;
                }
            } catch (Exception ex) {
                if (!localMonitor.Canceled)
                {
                    LoggingService.LogError(ex.ToString());
                    if (localMonitor.RunningTest != null)
                    {
                        RuntimeErrorCleanup(testContext, localMonitor.RunningTest, ex);
                    }
                    else
                    {
                        testContext.Monitor.ReportRuntimeError(null, ex);
                        throw ex;
                    }
                    result = UnitTestResult.CreateFailure(ex);
                }
                else
                {
                    result = UnitTestResult.CreateFailure(GettextCatalog.GetString("Canceled"), null);
                }
            } finally {
                testContext.Monitor.CancelRequested -= new TestHandler(rd.Cancel);
                runner.Dispose();
                System.Runtime.Remoting.RemotingServices.Disconnect(localMonitor);
            }

            return(result);
        }
		public static UnitTestResult CreateSuccess ()
		{
			UnitTestResult res = new UnitTestResult ();
			res.status = ResultStatus.Success;
			return res;
		}
Пример #28
0
        UnitTestResult RunWithConsoleRunner(ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext)
        {
            var          outFile = Path.GetTempFileName();
            LocalConsole cons    = new LocalConsole();

            try {
                LocalTestMonitor localMonitor = new LocalTestMonitor(testContext, test, suiteName, testName != null);

                if (!string.IsNullOrEmpty(cmd.Arguments))
                {
                    cmd.Arguments += " ";
                }
                cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath;

                bool automaticUpdates = cmd.Command.Contains("GuiUnit") || (cmd.Command.Contains("mdtool.exe") && cmd.Arguments.Contains("run-md-tests"));
                if (!string.IsNullOrEmpty(testName))
                {
                    cmd.Arguments += " -run=" + suiteName + "." + testName;
                }
                else if (!string.IsNullOrEmpty(suiteName))
                {
                    cmd.Arguments += " -run=" + suiteName;
                }
                if (automaticUpdates)
                {
                    var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener(localMonitor);
                    cmd.Arguments += " -port=" + tcpListener.Port;
                }
                var p = testContext.ExecutionContext.Execute(cmd, cons);

                testContext.Monitor.CancelRequested += p.Cancel;
                if (testContext.Monitor.IsCancelRequested)
                {
                    p.Cancel();
                }
                p.WaitForCompleted();

                if (new FileInfo(outFile).Length == 0)
                {
                    throw new Exception("Command failed");
                }

                XDocument doc = XDocument.Load(outFile);

                if (doc.Root != null)
                {
                    if (automaticUpdates)
                    {
                        DispatchService.GuiDispatch(delegate {
                            testContext.ResultsPad.InitializeTestRun(test);
                        });
                    }

                    var root = doc.Root.Elements("test-suite").FirstOrDefault();
                    if (root != null)
                    {
                        cons.SetDone();
                        var ot = cons.Out.ReadToEnd();
                        var et = cons.Error.ReadToEnd();
                        testContext.Monitor.WriteGlobalLog(ot);
                        if (!string.IsNullOrEmpty(et))
                        {
                            testContext.Monitor.WriteGlobalLog("ERROR:\n");
                            testContext.Monitor.WriteGlobalLog(et);
                        }

                        bool macunitStyle = doc.Root.Element("environment") != null && doc.Root.Element("environment").Attribute("macunit-version") != null;
                        return(ReportXmlResult(localMonitor, root, "", macunitStyle));
                    }
                }
                throw new Exception("Test results could not be parsed.");
            } catch (Exception ex) {
                cons.SetDone();
                var ot = cons.Out.ReadToEnd();
                var et = cons.Error.ReadToEnd();
                testContext.Monitor.WriteGlobalLog(ot);
                if (!string.IsNullOrEmpty(et))
                {
                    testContext.Monitor.WriteGlobalLog("ERROR:\n");
                    testContext.Monitor.WriteGlobalLog(et);
                }
                testContext.Monitor.ReportRuntimeError("Test execution failed.\n" + ot + "\n" + et, ex);
                return(UnitTestResult.CreateIgnored("Test execution failed"));
            } finally {
                File.Delete(outFile);
            }
        }
Пример #29
0
		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 ();
		}
Пример #30
0
        UnitTestResult ReportXmlResult(IRemoteEventListener listener, XElement elem, string testPrefix, bool macunitStyle)
        {
            UnitTestResult result = new UnitTestResult();
            var            time   = (string)elem.Attribute("time");

            if (time != null)
            {
                result.Time = TimeSpan.FromSeconds(double.Parse(time, CultureInfo.InvariantCulture));
            }
            result.TestDate = DateTime.Now;

            var reason = elem.Element("reason");

            if (reason != null)
            {
                result.Message = (string)reason;
            }

            var failure = elem.Element("failure");

            if (failure != null)
            {
                var msg = failure.Element("message");
                if (msg != null)
                {
                    result.Message = (string)msg;
                }
                var stack = failure.Element("stack-trace");
                if (stack != null)
                {
                    result.StackTrace = (string)stack;
                }
            }

            switch ((string)elem.Attribute("result"))
            {
            case "Error":
            case "Failure":
                result.Status = ResultStatus.Failure;
                break;

            case "Success":
                result.Status = ResultStatus.Success;
                break;

            case "Ignored":
                result.Status = ResultStatus.Ignored;
                break;

            default:
                result.Status = ResultStatus.Inconclusive;
                break;
            }

            if (elem.Name == "test-suite")
            {
                // nunitlite does not emit <test-suite type="Namespace" elements so we need to fake
                // them by deconstructing the full type name and emitting the suite started events manually
                var names = new List <string> ();
                if (!macunitStyle || (string)elem.Attribute("type") == "Assembly")
                {
                    names.Add("<root>");
                }
                else
                {
                    names.AddRange(elem.Attribute("name").Value.Split('.'));
                }

                for (int i = 0; i < names.Count; i++)
                {
                    listener.SuiteStarted(testPrefix + string.Join(".", names.Take(i + 1)));
                }

                var name = (string)elem.Attribute("type") == "Assembly" ? "<root>" : (string)elem.Attribute("name");
                var cts  = elem.Element("results");
                if (cts != null)
                {
                    foreach (var ct in cts.Elements())
                    {
                        var r = ReportXmlResult(listener, ct, name != "<root>" ? testPrefix + name + "." : "", macunitStyle);
                        result.Add(r);
                    }
                }
                for (int i = 0; i < names.Count; i++)
                {
                    listener.SuiteFinished(testPrefix + string.Join(".", names.Take(i + 1)), result);
                }
            }
            else
            {
                string name = (string)elem.Attribute("name");
                switch (result.Status)
                {
                case ResultStatus.Success:
                    result.Passed++;
                    break;

                case ResultStatus.Failure:
                    result.Failures++;
                    break;

                case ResultStatus.Ignored:
                    result.Ignored++;
                    break;

                case ResultStatus.Inconclusive:
                    result.Inconclusive++;
                    break;
                }

                listener.TestStarted(name);
                listener.TestFinished(name, result);
            }
            return(result);
        }
		void ClearResults ()
		{
			if (failuresTreeView.IsRealized)
				failuresTreeView.ScrollToPoint (0, 0);

			results.Clear ();

			error = null;
			errorMessage = null;

			failuresStore.Clear ();
			outputView.Buffer.Clear ();
			outIters.Clear ();
			progressBar.Fraction = 0;
			progressBar.Text = "";
			testsRun = 0;
			resultSummary = new UnitTestResult ();
			resultLabel.Markup = "";
			resultLabel.Hide ();
			labels.Show ();
			UpdateCounters ();
		}
Пример #32
0
        void FillTestInformation()
        {
            if (!detailsPad.Visible)
            {
                return;
            }

            if (detailsTest is UnitTestGroup)
            {
                UnitTestGroup group = detailsTest as UnitTestGroup;
                if (infoBook.Page == TestSummaryPage)
                {
                    detailsStore.Clear();
                    foreach (UnitTest t in group.Tests)
                    {
                        UnitTestResult res = t.Results.GetLastResult(chart.CurrentDate);
                        if (res != null)
                        {
                            detailsStore.AppendValues(t, t.Name, res.Passed.ToString(), res.ErrorsAndFailures.ToString(), res.Ignored.ToString());
                        }
                        else
                        {
                            detailsStore.AppendValues(t, t.Name, "", "", "");
                        }
                    }
                }
                else if (infoBook.Page == TestRegressionsPage)
                {
                    regressionStore.Clear();
                    UnitTestCollection regs = detailsTest.GetRegressions(chart.ReferenceDate, chart.CurrentDate);
                    if (regs.Count > 0)
                    {
                        foreach (UnitTest t in regs)
                        {
                            regressionStore.AppendValues(t, t.Name, TestStatusIcon.Failure);
                        }
                    }
                    else
                    {
                        regressionStore.AppendValues(null, GettextCatalog.GetString("No regressions found."));
                    }
                }
                else if (infoBook.Page == TestFailuresPage)
                {
                    failedStore.Clear();
                    UnitTestCollection regs = group.GetFailedTests(chart.CurrentDate);
                    if (regs.Count > 0)
                    {
                        foreach (UnitTest t in regs)
                        {
                            failedStore.AppendValues(t, t.Name, TestStatusIcon.Failure);
                        }
                    }
                    else
                    {
                        failedStore.AppendValues(null, GettextCatalog.GetString("No failed tests found."));
                    }
                }
            }
            else
            {
                UnitTestResult res = detailsTest.Results.GetLastResult(chart.CurrentDate);
                if (infoBook.Page == TestOutputPage)
                {
                    outputView.Buffer.Clear();
                    if (res != null)
                    {
                        outputView.Buffer.InsertAtCursor(res.ConsoleOutput);
                    }
                }
                else if (infoBook.Page == TestResultPage)
                {
                    resultView.Buffer.Clear();
                    if (res != null)
                    {
                        string msg = res.Message + "\n\n" + res.StackTrace;
                        resultView.Buffer.InsertAtCursor(msg);
                    }
                }
            }
        }
        void ITestProgressMonitor.EndTest(UnitTest test, UnitTestResult result)
        {
            if (test is UnitTestGroup)
                return;

            testsRun++;
            ResultRecord rec = new ResultRecord ();
            rec.Test = test;
            rec.Result = result;

            if (result.IsFailure) {
                testsFailed++;
            }
            if (result.IsIgnored) {
                testsIgnored++;
            }
            results.Add (rec);

            ShowTestResult (test, result);

            UpdateCounters ();
            progressBar.Fraction = ((double)testsRun / (double)testsToRun);
            progressBar.Text = testsRun + " / " + testsToRun;
        }
Пример #34
0
        void ShowTestResult(UnitTest test, UnitTestResult result)
        {
            if (result.IsSuccess)
            {
                if (!buttonSuccess.Active)
                {
                    return;
                }
                TreeIter testRow = failuresStore.AppendValues(CircleImage.Success, Escape(test.FullName), test);
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }
            if (result.IsFailure)
            {
                if (!buttonFailures.Active)
                {
                    return;
                }
                string   file       = test.SourceCodeLocation != null ? test.SourceCodeLocation.FileName + ":" + test.SourceCodeLocation.Line : null;
                TreeIter testRow    = failuresStore.AppendValues(CircleImage.Failure, Escape(test.FullName), test, file);
                bool     hasMessage = result.Message != null && result.Message.Length > 0;
                if (hasMessage)
                {
                    failuresStore.AppendValues(testRow, null, Escape(result.Message), test);
                }
                if (result.StackTrace != null && result.StackTrace.Length > 0)
                {
                    TreeIter row = testRow;
                    if (hasMessage)
                    {
                        row = failuresStore.AppendValues(testRow, null, GettextCatalog.GetString("Stack Trace"), test);
                    }
                    AddStackTrace(row, result.StackTrace, test);
                }
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }
            if (result.IsIgnored)
            {
                if (!buttonIgnored.Active)
                {
                    return;
                }
                TreeIter testRow = failuresStore.AppendValues(CircleImage.NotRun, Escape(test.FullName), test);
                if (result.Message != null)
                {
                    failuresStore.AppendValues(testRow, null, Escape(result.Message), test);
                }
                failuresTreeView.ScrollToCell(failuresStore.GetPath(testRow), null, false, 0, 0);
            }

            string   msg = GettextCatalog.GetString("Running {0} ...", test.FullName);
            TextIter it  = outputView.Buffer.EndIter;

            outIters [test] = it.Offset;
            outputView.Buffer.InsertWithTags(ref it, msg, bold);
            outputView.Buffer.Insert(ref it, "\n");
            if (result.ConsoleOutput != null)
            {
                outputView.Buffer.Insert(ref it, result.ConsoleOutput);
            }
            if (result.ConsoleError != null)
            {
                outputView.Buffer.Insert(ref it, result.ConsoleError);
            }
            outputView.ScrollMarkOnscreen(outputView.Buffer.InsertMark);
        }
Пример #35
0
		void IPadContent.Initialize (IPadWindow window)
		{
			this.window = window;
			
			DockItemToolbar toolbar = window.GetToolbar (PositionType.Top);
			
			buttonSuccess = new ToggleButton ();
			buttonSuccess.Label = GettextCatalog.GetString ("Successful Tests");
			buttonSuccess.Active = false;
			buttonSuccess.Image = new ImageView (TestStatusIcon.Success);
			buttonSuccess.Image.Show ();
			buttonSuccess.Toggled += new EventHandler (OnShowSuccessfulToggled);
			buttonSuccess.TooltipText = GettextCatalog.GetString ("Show Successful Tests");
			toolbar.Add (buttonSuccess);

			buttonInconclusive = new ToggleButton ();
			buttonInconclusive.Label = GettextCatalog.GetString ("Inconclusive Tests");
			buttonInconclusive.Active = true;
			buttonInconclusive.Image = new ImageView (TestStatusIcon.Inconclusive);
			buttonInconclusive.Image.Show ();
			buttonInconclusive.Toggled += new EventHandler (OnShowInconclusiveToggled);
			buttonInconclusive.TooltipText = GettextCatalog.GetString ("Show Inconclusive Tests");
			toolbar.Add (buttonInconclusive);
			
			buttonFailures = new ToggleButton ();
			buttonFailures.Label = GettextCatalog.GetString ("Failed Tests");
			buttonFailures.Active = true;
			buttonFailures.Image = new ImageView (TestStatusIcon.Failure);
			buttonFailures.Image.Show ();
			buttonFailures.Toggled += new EventHandler (OnShowFailuresToggled);
			buttonFailures.TooltipText = GettextCatalog.GetString ("Show Failed Tests");
			toolbar.Add (buttonFailures);

			buttonIgnored = new ToggleButton ();
			buttonIgnored.Label = GettextCatalog.GetString ("Ignored Tests");
			buttonIgnored.Active = true;
			buttonIgnored.Image = new ImageView (TestStatusIcon.NotRun);
			buttonIgnored.Image.Show ();
			buttonIgnored.Toggled += new EventHandler (OnShowIgnoredToggled);
			buttonIgnored.TooltipText = GettextCatalog.GetString ("Show Ignored Tests");
			toolbar.Add (buttonIgnored);
			
			buttonOutput = new ToggleButton ();
			buttonOutput.Label = GettextCatalog.GetString ("Output");
			buttonOutput.Active = false;
			buttonOutput.Image = ImageService.GetImage (MonoDevelop.Ide.Gui.Stock.OutputIcon, IconSize.Menu);
			buttonOutput.Image.Show ();
			buttonOutput.Toggled += new EventHandler (OnShowOutputToggled);
			buttonOutput.TooltipText = GettextCatalog.GetString ("Show Output");
			toolbar.Add (buttonOutput);
			
			toolbar.Add (new SeparatorToolItem ());
			
			buttonRun = new Button ();
			buttonRun.Label = GettextCatalog.GetString ("Rerun Tests");
			buttonRun.Image = new Gtk.Image (Gtk.Stock.Execute, IconSize.Menu);
			buttonRun.Image.Show ();
			buttonRun.Sensitive = false;
			toolbar.Add (buttonRun);
			
			buttonStop = new Button (new Gtk.Image (Ide.Gui.Stock.Stop, Gtk.IconSize.Menu));
			toolbar.Add (buttonStop);
			toolbar.ShowAll ();
			
			buttonStop.Clicked += new EventHandler (OnStopClicked);
			buttonRun.Clicked += new EventHandler (OnRunClicked);
			
			// Run panel
			
			DockItemToolbar runPanel = window.GetToolbar (PositionType.Bottom);
			
			infoSep = new VSeparator ();
			
			resultLabel.UseMarkup = true;
			infoCurrent.Ellipsize = Pango.EllipsizeMode.Start;
			infoCurrent.WidthRequest = 0;
			runPanel.Add (resultLabel);
			runPanel.Add (progressBar);
			runPanel.Add (infoCurrent, true, 10);	
			
			labels = new HBox (false, 10);
			
			infoLabel.UseMarkup = true;

			labels.PackStart (infoLabel, true, false, 0);

			runPanel.Add (new Gtk.Label (), true);
			runPanel.Add (labels);
			runPanel.Add (infoSep, false, 10);
			
			progressBar.HeightRequest = infoLabel.SizeRequest ().Height;
			runPanel.ShowAll ();
			resultSummary = new UnitTestResult ();
			UpdateCounters ();
		}
Пример #36
0
		public UnitTestResult GetLastResult ()
		{
			if (!resultLoaded) {
				resultLoaded = true;
				lastResult = Results.GetLastResult (DateTime.Now);
				if (lastResult != null)
					historicResult = true;
			}
			return lastResult;
		}
Пример #37
0
		public void InitializeTestRun (UnitTest test)
		{
			rootTest = test;
			results.Clear ();

			testsToRun = test.CountTestCases ();
			error = null;
			errorMessage = null;
			
			progressBar.Fraction = 0;
			progressBar.Text = "";
			progressBar.Text = "0 / " + testsToRun;
			testsRun = 0;
			resultSummary = new UnitTestResult ();
			UpdateCounters ();
			
			infoSep.Show ();
			infoCurrent.Show ();
			progressBar.Show ();
			resultLabel.Hide ();
			labels.Show ();
			buttonStop.Sensitive = true;
			buttonRun.Sensitive = false;

			if (failuresTreeView.IsRealized)
				failuresTreeView.ScrollToPoint (0, 0);
			
			failuresStore.Clear ();
			outputView.Buffer.Clear ();
			outIters.Clear ();
			cancel = false;
			Running = true;
			
			configuration = IdeApp.Workspace.ActiveConfigurationId;
			
			AddStartMessage ();
		}
Пример #38
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;
		}
Пример #39
0
		void ITestProgressMonitor.EndTest (UnitTest test, UnitTestResult result)
		{
			if (test is UnitTestGroup)
				return;
			
			testsRun++;
			ResultRecord rec = new ResultRecord ();
			rec.Test = test;
			rec.Result = result;
			
			resultSummary.Add (result);
			results.Add (rec);
			
			ShowTestResult (test, result);
			
			UpdateCounters ();

			double frac;
			if (testsToRun != 0)
				frac = ((double)testsRun / (double)testsToRun);
			else
				frac = 1;

			frac = Math.Min (1, Math.Max (0, frac));

			progressBar.Fraction = frac;
			progressBar.Text = testsRun + " / " + testsToRun;
		}
		public void Add (UnitTestResult test)
		{
			((IList)this).Add (test);
		}
Пример #41
0
		void ITestProgressMonitor.EndTest (UnitTest test, UnitTestResult result)
		{
			monitor.EndTest (test, result);
		}
Пример #42
0
/*		public override void GetNodeAttributes (ITreeNavigator parentNode, object dataObject, ref NodeAttributes attributes)
 *              {
 *                      attributes |= NodeAttributes.UseMarkup;
 *              }
 */
        public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon)
        {
            UnitTest test = dataObject as UnitTest;

            if (test.Status == TestStatus.Running)
            {
                icon  = CircleImage.Running;
                label = test.Title;
                return;
            }
            else if (test.Status == TestStatus.Loading)
            {
                icon  = CircleImage.Loading;
                label = test.Title + GettextCatalog.GetString(" (Loading)");
                return;
            }
            else if (test.Status == TestStatus.LoadError)
            {
                icon  = CircleImage.Failure;
                label = test.Title + GettextCatalog.GetString(" (Load failed)");
                return;
            }
            else
            {
                label = test.Title;

                UnitTestResult res = test.GetLastResult();
                if (res == null)
                {
                    icon = CircleImage.None;
                }
                else if (res.ErrorsAndFailures > 0 && res.Passed > 0)
                {
                    icon = test.IsHistoricResult ? CircleImage.OldSuccessAndFailure : CircleImage.SuccessAndFailure;
                }
                else if (res.IsInconclusive)
                {
                    icon = test.IsHistoricResult ? CircleImage.OldInconclusive : CircleImage.Inconclusive;
                }
                else if (res.IsFailure)
                {
                    icon = test.IsHistoricResult ? CircleImage.OldFailure : CircleImage.Failure;
                }
                else if (res.IsSuccess)
                {
                    icon = test.IsHistoricResult ? CircleImage.OldSuccess : CircleImage.Success;
                }
                else if (res.IsNotRun)
                {
                    icon = CircleImage.NotRun;
                }
                else
                {
                    icon = CircleImage.None;
                }

                if (res != null && treeBuilder.Options ["ShowTestCounters"] && (test is UnitTestGroup))
                {
                    label += string.Format(GettextCatalog.GetString(" ({0} passed, {1} failed, {2} not run)"), res.Passed, res.ErrorsAndFailures, res.TestsNotRun);
                }

                if (treeBuilder.Options ["ShowTestTime"])
                {
                    label += "   Time: {0}ms" + (res.Time.TotalMilliseconds);
                }
            }
        }
		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;
		}
Пример #44
0
/*		public override void GetNodeAttributes (ITreeNavigator parentNode, object dataObject, ref NodeAttributes attributes)
 *              {
 *                      attributes |= NodeAttributes.UseMarkup;
 *              }
 */
        public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon)
        {
            UnitTest test = dataObject as UnitTest;

            if (test.Status == TestStatus.Running)
            {
                icon  = CircleImage.Running;
                label = test.Title;
                return;
            }
            else if (test.Status == TestStatus.Loading)
            {
                icon  = CircleImage.Loading;
                label = test.Title + GettextCatalog.GetString(" (Loading)");
                return;
            }
            else if (test.Status == TestStatus.LoadError)
            {
                icon  = CircleImage.Failure;
                label = test.Title + GettextCatalog.GetString(" (Load failed)");
                return;
            }
            else
            {
                label = test.Title;

                UnitTestResult res = test.GetLastResult();
                if (res == null)
                {
                    icon = CircleImage.None;
                }
                else if (res.IsFailure && res.IsSuccess)
                {
                    icon = CircleImage.SuccessAndFailure;
                }
                else if (res.IsFailure)
                {
                    icon = CircleImage.Failure;
                }
                else if (res.IsSuccess)
                {
                    icon = CircleImage.Success;
                    if (treeBuilder.Options ["ShowTestTime"])
                    {
                        label += " (" + (res.Time.TotalMilliseconds) + " ms)";
                    }
                }
                else if (res.IsIgnored)
                {
                    icon = CircleImage.NotRun;
                }
                else
                {
                    icon = CircleImage.None;
                }

                if (res != null && treeBuilder.Options ["ShowTestCounters"] && (test is UnitTestGroup))
                {
                    label += string.Format(GettextCatalog.GetString(" ({0} success, {1} failed, {2} ignored)"), res.TotalSuccess, res.TotalFailures, res.TotalIgnored);
                }
            }
        }
		public void Add (UnitTestResult res)
		{
			Time += res.Time;
			Passed += res.Passed;
			Errors += res.Errors;
			Failures += res.Failures;
			Ignored += res.Ignored;
			Inconclusive += res.Inconclusive;
			Skipped += res.Skipped;
		}
Пример #46
0
 public void EndTest(UnitTest test, UnitTestResult result)
 {
     monitor.EndTest(test, result);
 }