zoukankan      html  css  js  c++  java
  • C#整合VS2010和NUnit

    软件下载

    .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 按钮就能运行测试用例了。从下图可以看到失败的测试用例显示的比较详细的信息。

  • 相关阅读:
    MySQL常用命令
    Jstack、Jmap命令简单使用
    MySQL慢查询日志ES索引模板
    MySQL二进制安装部署
    varnish启动报错
    基础训练 Sine之舞
    基础训练 FJ的字符串
    基础训练 芯片测试
    基础训练 龟兔赛跑预测
    基础训练 回形取数
  • 原文地址:https://www.cnblogs.com/fumj/p/2832704.html
Copyright © 2011-2022 走看看