软件下载

.Net单元测试工具 NUnit下载:http://www.nunit.org/index.php?p=download,最新的为NUnit-2.6.0.12051.msi,下载安装。

VS2010 NUnit 整合插件 Visual Nunit 2010下载:http://visualstudiogallery.msdn.microsoft.com/c8164c71-0836-4471-80ce-633383031099,下载安装完毕就能在 VS2010 的 view->Other Windows中看到 Visual Nunit了(或使用快捷键Ctrl + F7),打开该视图,将之拖到合适的位置。

测试程序

1,新建名为 NUnitSample 的C#控制台应用程序。在References中增加References:nunit.framework,路径默认为:C:\Program Files \NUnit 2.6\bin\framework\nunit.framewor.dll。

2,删除 Class1.cs,增加两个C#文件:NUnitSample.cs 和NUnitSampleTest.cs。其内容分别为:

// File: NUnitSample.cs
//
using System; namespace NUnitSample
{
public class MathUtil
{
public int Add(int a, int b)
{
return a + b;
} static void Main(string[] args)
{
}
}
}

// File: NUnitSampleTest.cs
//
using System;
using NUnit.Framework; namespace NUnitSample
{
[TestFixture]
public class NUnitSampleTest
{
[Test]
public void AddTest()
{
MathUtil util = new MathUtil();
int result = util.Add(4, 4);
Assert.AreEqual(8, result);
} [Test]
public void AddTestFailure()
{
MathUtil util = new MathUtil();
int result = util.Add(4, 4);
Assert.AreEqual(6, result);
}
}
}

在上面的代码中引用 NUnit.Framework,使用[TestFixture]表明这是用于测试的类,在其中使用 [Test]表示具体的测试用例,在这里添加了两个测试用例:一个成功的和一个失败的测试。

3,编译,然后点击 Visula Unit中的 Run 按钮就能运行测试用例了。从下图可以看到失败的测试用例显示的比较详细的信息。

C#整合VS2010和NUnit的更多相关文章

  1. 转:VS2010调试NUnit测试项目 (Running or debugging NUnit tests from Visual Studio without any extensions)

    If you write unit tests and use NUnit test framework this may be helpful. I decided to write this si ...

  2. Nunit工具做C#的单元测试

      Nunit工具做C#的单元测试 学习心得 编写人:罗旭成 时间:2013年9月2日星期一 1.开发人员如何做单元测试 单元测试是针对最小的可测试软件元素(单元)的,它所测试的内容包括单元的内部结构 ...

  3. NUnit单元测试资料汇总

    NUnit单元测试资料汇总 从安装到配置 首先到官网http://www.nunit.org/下载如下图的资料,安装NUnit-2.6.1.msi包. 然后挂在VS2010外部工具这个地方来使用,工具 ...

  4. NUnit单元测试笔记

    vs2010 和 NUnit 问题处理. . 在 <configuration> 下 加 ... <startup> <requiredRuntime version=& ...

  5. 实现VS2010整合NUnit进行单元测试(转载)

    代码编写,单元测试必不可少,简单谈谈Nunit进行单元测试的使用方式: 1.下载安装NUnit(最新win版本为NUnit-2.6.4.msi) http://www.nunit.org/index. ...

  6. 5分钟实现VS2010整合NUnit进行单元测试

    本文转载自:http://www.cnblogs.com/jeffwongishandsome/archive/2012/03/18/2404845.html 1.下载安装NUnit(最新win版本为 ...

  7. 实现VS2010整合NUnit进行单元测试

    1.下载安装NUnit(最新win版本为NUnit.3.2.1.msi) http://www.nunit.org/index.php?p=download 2.下载并安装VS的Visual Nuni ...

  8. VS2010整合NUnit进行单元测试

    1.下载安装NUnit(最新win版本为NUnit-2.6.0.12051.msi) http://www.nunit.org/index.php?p=download 2.下载并安装VS的Visua ...

  9. [转] VS 整合NUnit进行单元测试

    Jeff Wong原文 5分钟实现VS2010整合NUnit进行单元测试 1.下载安装NUnit(最新win版本为NUnit-2.6.0.12051.msi) http://www.nunit.org ...

随机推荐

  1. Spring Boot/Spring Cloud、ESB、Dubbo

    如何使用Spring Boot/Spring Cloud 实现微服务应用spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现. ...

  2. 添加mysamba

    一. 复制/home/tingpan/openwrt/barrier_breaker/feeds/luci/applications文件夹下的luci-samba文件,将文件中的内容samba改为my ...

  3. 【python】break和continue

    break:跳出循环 ,continue:停止当前循环,进入下一次循环,但为跳出循环. passwdList=["123","456"] valid = Fal ...

  4. MySQL 报错记录

    #--------------------------------------------------------------------------------------------------- ...

  5. 利用Red Blob游戏介绍A*算法

    转自:http://gad.qq.com/program/translateview/7194337 在游戏中,我们经常想要找到从一个位置到另一个位置的路径.我们不只是想要找到最短距离,同时也要考虑旅 ...

  6. Effect

    /////////////////////////////////shader source/////////////////////////////////Texture2D colorMap : ...

  7. sqoop操作之HIVE导出到ORACLE

    示例数据准备 hive中创建dept表 create table dept( deptno int, dname string, loc string ) row format delimited f ...

  8. HTML5中常用的标签(及标签的属性和作用)

    1.标签:<!DOCTYPE>作用:声明是文档中的第一成分,位于<html>标签之前. 2.标签:<html>作用:此元素可告知浏览器其自身是一个HTML文档.属性 ...

  9. 《图像处理实例》 之 目标旋转矫正(基于区域提取、DFT变换)

    目标:1.把矩形旋转正.          2.把文字旋转校正.                                                                     ...

  10. 用多个class选择元素

    注意下面两个的区别:  $(".role-developer.role-designer").css("color","red");  $( ...