当前位置: 首页>>代码示例>>C#>>正文


C# UnitTest.GetLastResult方法代码示例

本文整理汇总了C#中MonoDevelop.NUnit.UnitTest.GetLastResult方法的典型用法代码示例。如果您正苦于以下问题:C# UnitTest.GetLastResult方法的具体用法?C# UnitTest.GetLastResult怎么用?C# UnitTest.GetLastResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoDevelop.NUnit.UnitTest的用法示例。


在下文中一共展示了UnitTest.GetLastResult方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsGoToFailureEnabled

		bool IsGoToFailureEnabled (UnitTest test)
		{
			if (test.SourceCodeLocation == null || test is UnitTestGroup)
				return false;

			UnitTestResult res = test.GetLastResult ();
			return res != null && res.IsFailure;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:8,代码来源:TestNodeBuilder.cs

示例2: RunWithConsoleRunner

		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) {
					using (var p = testContext.ExecutionContext.Execute (cmd, cons)) {
						testContext.Monitor.CancelRequested += p.Cancel;
						if (testContext.Monitor.IsCancelRequested)
							p.Cancel ();
						p.WaitForCompleted ();
						testContext.Monitor.CancelRequested -= p.Cancel;
					}
					
					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);
				cons.Dispose ();
			}
		}
开发者ID:riverans,项目名称:monodevelop,代码行数:83,代码来源:NUnitAssemblyTestSuite.cs

示例3: RunWithConsoleRunner

		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, suiteName);
					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");

				if (automaticUpdates) {
					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);
			}
		}
开发者ID:raybarrera,项目名称:monodevelop,代码行数:74,代码来源:NUnitAssemblyTestSuite.cs


注:本文中的MonoDevelop.NUnit.UnitTest.GetLastResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。