本文整理汇总了C#中NUnit类的典型用法代码示例。如果您正苦于以下问题:C# NUnit类的具体用法?C# NUnit怎么用?C# NUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NUnit类属于命名空间,在下文中一共展示了NUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NUnitExecute
public void NUnitExecute()
{
#region Find NUnit installation
string nunitPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
nunitPath = Path.Combine(nunitPath, NUnit.DEFAULT_NUNIT_DIRECTORY);
RegistryKey buildKey = Registry.ClassesRoot.OpenSubKey(@"NUnitTestProject\shell\open\command");
if (buildKey == null) Assert.Ignore(@"Can't find NUnit installation");
nunitPath = buildKey.GetValue(null, nunitPath).ToString();
Regex nunitRegex = new Regex("(.+)nunit-gui\\.exe", RegexOptions.IgnoreCase);
Match pathMatch = nunitRegex.Match(nunitPath);
nunitPath = pathMatch.Groups[1].Value.Replace("\"", "");
#endregion Find NUnit installation
MockBuild buildEngine = new MockBuild();
string testDirectory = TaskUtility.makeTestDirectory(buildEngine);
NUnit task = new NUnit();
task.BuildEngine = buildEngine;
task.Assemblies = TaskUtility.StringArrayToItemArray(
Path.Combine(nunitPath, "nunit.framework.tests.dll"));
task.WorkingDirectory = testDirectory;
task.OutputXmlFile = Path.Combine(testDirectory, @"nunit.framework.tests-results.xml");
Assert.IsTrue(task.Execute(), "Execute Failed");
}
示例2: LoadSettings
public void LoadSettings(NUnit.Util.ISettings settings)
{
this.settings = settings;
TabInfoCollection info = new TabInfoCollection();
string tabList = (string)settings.GetSetting( Prefix + "TabList" );
if ( tabList != null )
{
string[] tabNames = tabList.Split( new char[] { ',' } );
foreach( string name in tabNames )
{
string prefix = Prefix + name;
string text = (string)settings.GetSetting(prefix + ".Title");
if ( text == null )
break;
TabInfo tab = new TabInfo( name, text );
tab.Content = (TextDisplayContent)settings.GetSetting(prefix + ".Content", TextDisplayContent.Empty );
tab.Enabled = settings.GetSetting( prefix + ".Enabled", true );
info.Add( tab );
}
}
if ( info.Count > 0 )
tabInfo = info;
else
LoadDefaults();
}
示例3: NUnitAssemblyTest
/// <summary>
/// Creates an NUnit assembly-level test.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <param name="runner">The NUnit test runner.</param>
public NUnitAssemblyTest(IAssemblyInfo assembly, NUnit.Core.TestRunner runner)
: base(assembly.Name, assembly, runner.Test)
{
Kind = TestKinds.Assembly;
this.runner = runner;
}
示例4: AfterTest
/// <summary>
/// Method gets called once at the end of running the tests
/// </summary>
public override void AfterTest(NUnit.Framework.TestDetails testDetails)
{
if (Environment.OSVersion.Platform != PlatformID.Unix &&
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILDAGENT_SUBKEY")))
{
// End redirection. Otherwise test might fail when we run them multiple
// times in NUnit.
RegOverridePredefKey(HKEY_CURRENT_USER, UIntPtr.Zero);
}
base.AfterTest(testDetails);
}
示例5: BeforeTest
/// <summary>
/// Method gets called once at the very start of running the tests
/// </summary>
public override void BeforeTest(NUnit.Framework.TestDetails testDetails)
{
base.BeforeTest(testDetails);
if (Environment.OSVersion.Platform != PlatformID.Unix &&
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILDAGENT_SUBKEY")))
{
UIntPtr hKey;
RegCreateKey(HKEY_CURRENT_USER, TmpRegistryKey, out hKey);
RegOverridePredefKey(HKEY_CURRENT_USER, hKey);
RegCloseKey(hKey);
}
}
示例6: SuiteFinished
public void SuiteFinished(NUnit.Core.TestResult result)
{
if(result.FullName.Equals(myRootName))
{
return;
}
JSONClass jsonClass = new JSONClass();
jsonClass.Add("name", result.Name);
jsonClass.Add("uuid", myUUID);
jsonClass.Add("type", "SuiteFinished");
ConsuloIntegration.SendToConsulo("unityTestState", jsonClass);
}
示例7: SuiteFinished
public void SuiteFinished(NUnit.Core.TestResult result)
{
if ((result.IsError || result.IsFailure) &&
(result.FailureSite == FailureSite.SetUp || result.FailureSite == FailureSite.TearDown))
{
testLog.SendMessage(
TestMessageLevel.Error,
string.Format("{0} failed for test fixture {1}", result.FailureSite, result.FullName));
if (result.Message != null)
testLog.SendMessage(TestMessageLevel.Error, result.Message);
if (result.StackTrace != null)
testLog.SendMessage(TestMessageLevel.Error, result.StackTrace);
}
}
示例8: SuiteStarted
public void SuiteStarted(NUnit.Core.TestName testName)
{
if(myRootName == null)
{
myRootName = testName.FullName;
return;
}
JSONClass jsonClass = new JSONClass();
jsonClass.Add("uuid", myUUID);
jsonClass.Add("name", testName.Name);
jsonClass.Add("type", "SuiteStarted");
ConsuloIntegration.SendToConsulo("unityTestState", jsonClass);
}
示例9: WriteActualValueTo
public override void WriteActualValueTo(NUnit.Framework.Constraints.MessageWriter writer)
{
int lines = Math.Min(expectedLines.Length, actualLines.Length);
for (int i = 0; i < lines; i++)
{
string expectedLine = expectedLines[i];
string actualExLine = actualLines[i];
if (!(expectedLine.Equals(actualExLine)))
{
writer.WriteActualValue(actualExLine + ", line " + (i + 1).ToString() + Environment.NewLine + expected);
return;
}
}
writer.WriteActualValue("actual text is " + actualLines.Length + " lines");
}
示例10: WaitForMessageBox
/// <summary>
/// The delegate to handle the message box is installed.
/// </summary>
/// <param name="cmd">Contains a NUnit.Extensions.Forms.MessageBoxTester.Command to
/// insert the desired reaction.</param>
public void WaitForMessageBox(NUnit.Extensions.Forms.MessageBoxTester.Command cmd)
{
lastMessageTitle = "";
lastMessageText = "";
ModalFormHandler = delegate(string name, IntPtr hWnd, Form form)
{
MessageBoxTester tester = new MessageBoxTester(hWnd);
System.Console.WriteLine("Title: " + tester.Title);
System.Console.WriteLine("Message: " + tester.Text);
lastMessageTitle = tester.Title;
lastMessageText = tester.Text;
tester.SendCommand(cmd);
};
}
示例11: NUnitExecuteWhenToolPathIsDefined
public void NUnitExecuteWhenToolPathIsDefined(int majorVersion, int minorVersion, int number)
{
string nUnitDirName = string.Format("NUnit {0}.{1}.{2}", majorVersion, minorVersion, number);
string nunitPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), nUnitDirName), "bin");
if (!Directory.Exists(nunitPath))
{
Assert.Inconclusive("{0} - not found", nunitPath);
}
MockBuild buildEngine = new MockBuild();
string testDirectory = TaskUtility.makeTestDirectory(buildEngine);
NUnit task = new NUnit();
task.ToolPath = nunitPath;
task.BuildEngine = buildEngine;
task.Assemblies = TaskUtility.StringArrayToItemArray(Path.Combine(nunitPath, "nunit.framework.tests.dll"));
task.WorkingDirectory = testDirectory;
Assert.IsTrue(task.Execute(), "Execute Failed");
}
示例12: WriteDescriptionTo
public override void WriteDescriptionTo(NUnit.Framework.Constraints.MessageWriter writer)
{
if (expected == null || actualEx == null)
{
writer.WriteExpectedValue(expected);
}
else
{
int lines = Math.Min(expectedLines.Length, actualLines.Length);
for (int i = 0; i < lines; i++)
{
string expectedLine = expectedLines[i];
string actualExLine = actualLines[i];
if (!(expectedLine.Equals(actualExLine)))
{
writer.WriteExpectedValue(expectedLine);
return;
}
}
writer.WriteExpectedValue("expected text is " + expectedLines.Length + " lines");
}
}
示例13: ParseTestList
private UnitTestResult[] ParseTestList ( NUnit.Core.Test test, string currentAssemblyPath )
{
if (test.IsSuite)
{
var tests = new List<UnitTestResult> ();
foreach (var obj in test.Tests)
{
if (obj is TestAssembly && File.Exists ((obj as TestAssembly).TestName.FullName))
currentAssemblyPath = (obj as TestAssembly).TestName.FullName;
if (obj is NUnit.Core.Test)
{
var results = ParseTestList (obj as NUnit.Core.Test, currentAssemblyPath);
tests.AddRange (results);
}
}
return tests.ToArray ();
}
else
{
return new[] { CreateNewTestResult (test as TestMethod, currentAssemblyPath) };
}
}
示例14: SuiteFinished
public void SuiteFinished(NUnit.Core.TestResult result)
{
}
示例15: RunFinished
public void RunFinished(NUnit.Core.TestResult result)
{
}