• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • NUnit --- 從零開始

    發表于:2009-04-08來源:作者:點擊數: 標簽:nunitNUnitNunit
    既然是從零開始,就先介紹一下 NUnit (http://www.nunit.org):一個.NET 框架下的 單元測試 框架,提供了類似于 JUnit 的功能,也是 .NET 框架下開發者應用最廣泛的單元 測試框架 之一(其他的還包括 CSUnit 等等)。 它的基本原理是通過 .NET 的反射機制
      既然是從零開始,就先介紹一下NUnit (http://www.nunit.org):一個.NET 框架下的單元測試框架,提供了類似于 JUnit的功能,也是 .NET 框架下開發者應用最廣泛的單元測試框架之一(其他的還包括 CSUnit 等等)。

            它的基本原理是通過.NET 的反射機制,利用代碼中的元數據(Attribute)來辨識到底有哪些單元測試。單元測試Unit Test)是測試驅動開發Test-Driven Development,TDD)很重要的一環,而TDD又是敏捷開發方法(比如極限編程--eXtreme Programming)的重要組成部分…… 總之,單元測試很重要就對了。 ^_^ (有關TDD、XP的詳細介紹在博客園的很多blog上就有,當然 google 上就更多了)

    例子開始:

    1。下載、安裝 NUnit(最新版可能是 2.2.0)

    2。很重要的步驟:測試一下 NUnit 是否安裝成功。

            方法:打開 NUnit,File--Open--選 NUnit 安裝目錄下的bin目錄中的 nunit.tests.dll。這時NUnit 主窗口左部的樹型列表中會出現很多個測試的名字,然后點 Run 按鈕,接著測試就開始運行了,直到 NUnit 主窗口左部的樹型列表中所有的測試前面都變成綠色,那就是成功了。(失敗的測試會有紅色的提示,沒有運行的測試會有黃色的提示。在這一步中,有可能 Console Runner 那個測試集合會出現問題。萬一出現問題,重啟一下 NUnit 再 Run,一般都是沒問題的) 
           

    2。怎么在開發中使用 NUnit 框架? 
            1)打開VS.NET 2003,新建一個 C# 的 Console 項目,在項目的 References 添加 nunit.framework(References 在 Solution Explorer 窗口中,右鍵,Add Reference...)

        2)隨便寫一個類

    public class Aclearcase/" target="_blank" >ccount    // 銀行帳戶類
    {
        private float balance; // 賬戶的余額

        public void Deposit(float amount)    // 存錢
        {
            balance+=amount;
        }

        public void Withdraw(float amount)    //取錢
        {
            balance-=amount;
        }

        public void TransferFunds(Account destination, float amount) // 轉賬
        {
            destination.Deposit(amount);
            Withdraw(amount);
        }
     
        public float Balance
        {
            get{ return balance;}
        }
        public static void Main(string[] args) 
        {
            Account source = new Account();    // 新建個賬戶
            source.Deposit(200.00F);    // 存200
            Account destination = new Account();    // 又建了一個
            destination.Deposit(150.00F);    // 存150
            source.TransferFunds(destination, 100.00F);    // 第一個賬戶轉給第二個100
        }
    }

       

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>