VS2010和NUnit整合
来源:互联网 发布:中国网络直销公司排名 编辑:程序博客网 时间:2024/05/22 03:54
1
下载安装NUnit(最新win版本为NUnit-2.6.0.12051.msi)http://www.nunit.org/index.php?p=download
2
下载并安装VS的Visual Nunit 2010插件
http://visualstudiogallery.msdn.microsoft.com/c8164c71-0836-4471-80ce-633383031099
注:可通过VS的“视图”->“其他窗口”找到并打开该插件(快捷键:Ctrl+F7)
3
新建测试项目(示例为简单的控制台应用程序),引入nunit.framework类库,默认安装后文件所在路径:
C:\Program Files \NUnit2.6\bin\framework\nunit.framewor.dll
4
测试代码准备:
namespace ConsoleApplication1
{
/// <summary>
/// 需要测试的方法
/// </summary>
public class TestMethods
{
public int Add(int a, int b)
{
return (a + b);
}
public bool ReturnBool(int i)
{
return (i == 1);
}
}
}
using NUnit.Framework;
namespace ConsoleApplication1
{
[TestFixture]
class Program
{
[Test]
public void TestAdd01()
{
TestMethods t = new TestMethods();
int result = t.Add(1, 1);
Assert.AreEqual(2, result);
}
[Test]
public void TestAdd02()
{
TestMethods t = new TestMethods();
int result = t.Add(1, 1);
Assert.AreEqual(3, result);
}
[Test]
public void TestBool01()
{
TestMethods t = new TestMethods();
Assert.IsTrue(t.ReturnBool(1));
}
[Test]
public void TestBool02()
{
TestMethods t = new TestMethods();
Assert.IsTrue(t.ReturnBool(2));
}
// 因为是控制台应用程序,所以需要一个入口
public static void Main(String[] args)
{
}
}
}
5 测试开始:
点击Run,正确与否立刻现行:
看结果:
我们在测试程序中故意出错的打了叉。简单吧。当然,还需要深入研究。
值得注意的是,我们在对真是项目测试的时候,有时候需要用到数据库链接,而我们一般将数据库链接放到Web.config里面,在通过
System.Configuration.ConfigurationSettings.AppSettings["con"].ToString()去取得。但是这样在测试中是读不到这个值的,所以测试的时候要把链接写成固定字符串。
参考地址:
http://www.cnblogs.com/jeffwongishandsome/archive/2012/03/18/2404845.html
- VS2010和NUnit整合
- VS2010整合NUnit进行调试
- VS2010整合NUnit进行单元测试
- VS2010整合NUnit进行单元测试
- nunit和vs2010
- Vs2010和Nnit的整合
- VS10中Nunit的整合
- SVN安装以及和VS2010整合使用
- SVN安装以及和VS2010整合使用
- VS2010使用Nunit的断点功能
- NUnit
- Nunit
- NUNIT
- NUnit
- 关于nunit调试VS2010中的4.0程序集的问题
- vs2010中使用Nunit测试c#代码结果的正确性
- vs2010中使用Nunit测试c#代码结果的正确性
- NUNIT VS2010 .NET 4.0 无法断点调试的问题
- 交叉编译opencv2.31与移植至arm9
- 文件锁 fcntl()函数说明
- 贪心算法 安排活动的问题 最大限度的利用有限资源
- 编程之美--求数组的子数组之和的最大值
- Visual C++线程同步技术剖析
- VS2010和NUnit整合
- 改善C#程序的若干建议
- 化妆品税率不变 部分电子产品调税会便宜
- POJ 1442 优先队列
- 安卓巴士Android开发神贴整理
- Java中使用hql,sql查询返回的list<Object> 转成需要的实体对象--方法讲解!
- 浏览器不能访问本地资源的限制
- ms-sql2005日志空间满解决方法
- see register with gdb