用NUnit為.NET程式做測試 — 常用測試屬性之三 Category

來源:互聯網
上載者:User

用NUnit為我們的.net程式做測試已經幾天了,大家在使用的時候有沒有注意到 NUnit 的左側邊欄裡還有一個前面沒有用到的東東呢?

這個就是Categories,分類。點擊開啟這個項目:

空空如也。別著急。下面我們就來認識這個Categories吧。我們在TestDivide()添加上 [Category("Category A")]

[Test][Category("Category A")]//[ExpectedException(typeof(DivideByZeroException))]public void TestDivide(){    int result = cal.Divide(a, b);    Assert.AreEqual(5, result);}

 

編譯,再看看Categories吧,是不是出來了一個 Category A ?

點擊Add將Category A添加到 Selected Categories中吧。

我們再次切換到Test選項卡,選擇整個測試專案,點擊Run,發現只有Category A的 TestDivide()Run過了。

 

上中,下面的複選框的意思是排除 在 Selected Categories中的組。也就是如果選擇複選框這些組別將不會在NUnit中Run

 

在測試中我們可以把我們的測試方法分成很多的Category來分別的測試或者不測試。這個比前面說到的Ignore和Explicit屬性強悍多了吧。

 

在明天我們繼續用實戰來練習我們前面學到的知識吧!!!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.