D:\\Program Files\\SharpDevelop\\2.2\\bin\\Tools\\NUnit
并且在SharpDevelop中可建立专门的Unit Test文件
默认建立如下所示的Nunit单元测试代码框架:
/*
* Created by SharpDevelop.
* User: user
* Date: 2008-1-4
* Time: 9:12
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
namespace Test1
{
[TestFixture]
public class Test1
{
[Test]
public void TestMethod()
{
// TODO: Add your test.
}
}
}
假设我在MainForm中有如下需要测试的代码:
public int add(int i,int j)
{
return i+j;
}
则可在Test1中方便地添加如下所示的单元测试代码:
[TestFixture]
public class Test1
{
[Test]
public void TestMethod()
{
// TODO: Add your test.
MainForm f = new MainForm();
Assert.AreEqual(2,f.add(1,1),\"1+1=2\");
}
}
但是,如果直接就这样编译会报错,提示找不到NUnit,需要在Project中的Reference添加对nunit.framework.dll的引用。
可手工添加,也可通过选择“View | Tools | Unit Test”,在出现的“Unit Test”管理界面中按“add reference to Nunit to current project”添加。 [Page]
运行单元测试,可通过在测试方法中点右键,选择“current method | unit tests | run in unit test pad”运行,也可通过选择“View | Tools | Unit Test”,在出现的“Unit Test”管理界面中运行。
运行结果信息显示在OutPut界面中:
\"D:\\Program Files\\SharpDevelop\\2.2\\bin\\..\\bin\\Tools\\NUnit\\nunit-console.exe\" \"D:\\OpenSourceTestTool\\SharpDevelop\\Test1\\bin\\Debug\\Test1.exe\" /results=\"C:\\Documents and Settings\\user\\Local Settings\\Temp\\tmp24B.tmp\" /fixture=\"Test1.Test1\" /testMethodName=\"Test1.Test1.TestMethod\"
NUnit version 2.4.2
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 5.1.2600 Service Pack 2
CLR Version: 2.0.50727.42 ( Net 2.0.50727.42 )
.
Tests run: 1, Failures: 0, Not run: 0, Time: 0.351 seconds
文章来源于领测软件测试网 https://www.ltesting.net/