本文整理汇总了C#中MonoDevelop.NUnit.UnitTest类的典型用法代码示例。如果您正苦于以下问题:C# UnitTest类的具体用法?C# UnitTest怎么用?C# UnitTest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitTest类属于MonoDevelop.NUnit命名空间,在下文中一共展示了UnitTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunUnitTest
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) {
var 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);
} else {
filter = new TestNameFilter (CollectTests ((UnitTestGroup)test));
}
} else {
filter = new TestNameFilter (test.TestId);
}
}
RunData rd = new RunData ();
rd.Runner = runner;
rd.Test = this;
rd.LocalMonitor = localMonitor;
testContext.Monitor.CancelRequested += new TestHandler (rd.Cancel);
UnitTestResult result;
var crashLogFile = Path.GetTempFileName ();
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, crashLogFile);
if (testName != null)
result = localMonitor.SingleTestResult;
ReportCrash (testContext, crashLogFile);
} catch (Exception ex) {
if (ReportCrash (testContext, crashLogFile)) {
result = UnitTestResult.CreateFailure (GettextCatalog.GetString ("Unhandled exception"), null);
}
else if (!localMonitor.Canceled) {
LoggingService.LogError (ex.ToString ());
if (localMonitor.RunningTest != null) {
RuntimeErrorCleanup (testContext, localMonitor.RunningTest, ex);
} else {
testContext.Monitor.ReportRuntimeError (null, ex);
throw;
}
result = UnitTestResult.CreateFailure (ex);
} else {
result = UnitTestResult.CreateFailure (GettextCatalog.GetString ("Canceled"), null);
}
} finally {
File.Delete (crashLogFile);
testContext.Monitor.CancelRequested -= new TestHandler (rd.Cancel);
runner.Dispose ();
System.Runtime.Remoting.RemotingServices.Disconnect (localMonitor);
}
return result;
}
示例2: XUnitExecutionSession
public XUnitExecutionSession (UnitTest unitTest, bool reportToMonitor)
{
this.reportToMonitor = reportToMonitor;
this.unitTest = unitTest;
result = new UnitTestResult ();
childSessions = new List<XUnitExecutionSession> ();
}
示例3: RegisterResult
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);
}
示例4: UnitTestOptionsDialog
public UnitTestOptionsDialog(Gtk.Window parent, UnitTest test)
: base(parent, null, null)
{
IAddInTreeNode node = AddInTreeSingleton.AddInTree.GetTreeNode("/SharpDevelop/Workbench/UnitTestOptions/GeneralOptions");
configurationNode = AddInTreeSingleton.AddInTree.GetTreeNode("/SharpDevelop/Workbench/UnitTestOptions/ConfigurationProperties");
this.test = test;
this.Title = GettextCatalog.GetString ("Unit Test Options");
properties = new DefaultProperties();
properties.SetProperty ("UnitTest", test);
AddNodes (properties, Gtk.TreeIter.Zero, node.BuildChildItems (this));
SelectFirstNode ();
}
示例5: NUnitOptionsWidget
public NUnitOptionsWidget (Properties customizationObject)
{
Build ();
test = ((Properties)customizationObject).Get<UnitTest> ("UnitTest");
config = ((Properties)customizationObject).Get<string> ("Config");
options = localOptions = (NUnitCategoryOptions) test.GetOptions (typeof(NUnitCategoryOptions), config);
store = new TreeStore (typeof(string));
categoryTree.Model = store;
categoryTree.HeadersVisible = false;
CellRendererText tr = new CellRendererText ();
tr.Editable = true;
tr.Edited += new EditedHandler (OnCategoryEdited);
textColumn = new TreeViewColumn ();
textColumn.Title = GettextCatalog.GetString ("Category");
textColumn.PackStart (tr, false);
textColumn.AddAttribute (tr, "text", 0);
textColumn.Expand = true;
categoryTree.AppendColumn (textColumn);
if (test.Parent != null)
useParentCheck.Active = !test.HasOptions (typeof(NUnitCategoryOptions), config);
else {
useParentCheck.Active = false;
useParentCheck.Sensitive = false;
}
if (!options.EnableFilter)
noFilterRadio.Active = true;
else if (options.Exclude)
excludeRadio.Active = true;
else
includeRadio.Active = true;
Fill ();
noFilterRadio.Toggled += new EventHandler (OnFilterToggled);
includeRadio.Toggled += new EventHandler (OnFilterToggled);
excludeRadio.Toggled += new EventHandler (OnFilterToggled);
useParentCheck.Toggled += new EventHandler (OnToggledUseParent);
addButton.Clicked += new EventHandler (OnAddCategory);
removeButton.Clicked += new EventHandler (OnRemoveCategory);
}
示例6: GetNextResult
public UnitTestResult GetNextResult (string configuration, UnitTest test, DateTime date)
{
DateTime currentDate = date;
TestRecord root = GetRootRecord (configuration, currentDate);
if (root == null)
root = GetNextRootRecord (configuration, ref currentDate);
while (root != null) {
TestRecord tr = FindRecord (root, test.StoreRelativeName);
if (tr != null && tr.Results != null) {
foreach (UnitTestResult res in tr.Results) {
if (res.TestDate > date)
return res;
}
}
root = GetNextRootRecord (configuration, ref currentDate);
}
return null;
}
示例7: UnitTestOptionsDialog
public UnitTestOptionsDialog (Gtk.Window parent, Properties properties) : base (parent, properties, "/MonoDevelop/NUnit/UnitTestOptions/GeneralOptions", false)
{
this.Title = GettextCatalog.GetString ("Unit Test Options");
test = properties.Get<UnitTest>("UnitTest");
configurationNode = AddinManager.GetExtensionNode("/MonoDevelop/NUnit/UnitTestOptions/ConfigurationOptions");
TreeIter iter;
if (store.GetIterFirst (out iter)) {
OptionsDialogSection section = store.GetValue (iter, 0) as OptionsDialogSection;
if (section != null && section.Id == "Configurations") {
FillConfigurations (iter);
}
}
ExpandCategories ();
if (firstSection != null)
ShowPage (firstSection);
}
示例8: GetSourceCodeLocation
internal SourceCodeLocation GetSourceCodeLocation(UnitTest test)
{
if (test is NUnitTestCase) {
NUnitTestCase t = (NUnitTestCase) test;
return GetSourceCodeLocation (t.ClassName, t.Name);
} else if (test is NUnitTestSuite) {
NUnitTestSuite t = (NUnitTestSuite) test;
return GetSourceCodeLocation (t.ClassName, null);
} else
return null;
}
示例9: OnRunChildTest
protected virtual UnitTestResult OnRunChildTest (UnitTest test, TestContext testContext)
{
return test.Run (testContext);
}
示例10: 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 ();
}
}
示例11: SearchTest
UnitTest SearchTest (UnitTest test, string fullName)
{
if (test == null)
return null;
if (test.FullName == fullName)
return test;
UnitTestGroup group = test as UnitTestGroup;
if (group != null) {
foreach (UnitTest t in group.Tests) {
UnitTest result = SearchTest (t, fullName);
if (result != null)
return result;
}
}
return null;
}
示例12: ClearRunningStatus
void ClearRunningStatus(UnitTest t)
{
t.Status = TestStatus.Ready;
UnitTestGroup group = t as UnitTestGroup;
if (group == null) return;
foreach (UnitTest ct in group.Tests)
ClearRunningStatus (ct);
}
示例13: ShowOptionsDialog
public static void ShowOptionsDialog (UnitTest test)
{
Properties properties = new Properties ();
properties.Set ("UnitTest", test);
using (var dlg = new UnitTestOptionsDialog (IdeApp.Workbench.RootWindow, properties))
MessageService.ShowCustomDialog (dlg);
}
示例14: FindTestNode
ITreeNavigator FindTestNode (UnitTest t)
{
ITreeNavigator nav = TreeView.GetNodeAtObject (t);
if (nav != null)
return nav;
if (t.Parent == null)
return null;
nav = FindTestNode (t.Parent);
if (nav == null)
return null;
nav.MoveToFirstChild (); // Make sure the children are created
return TreeView.GetNodeAtObject (t);
}
示例15: RunTest
public IAsyncOperation RunTest (UnitTest test, IExecutionHandler mode)
{
return RunTest (FindTestNode (test), mode, false);
}