您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > Nunit
單元測試工具Nunit基本用法
作者:網(wǎng)絡轉(zhuǎn)載 發(fā)布時間:[ 2013/3/18 14:19:07 ] 推薦標簽:

  除方法可設置Category,連TestFixture都可以設置Category,如,對于一些整個TestFixture都測試時間都很長的,可將它設置為[Category"Long")],這樣沒有必要重復標記每個測試方法了。

  9.每個測試的運行都應該是互相獨立的;可在任何時候,任意順序運行每個單獨的測試。
  10.NUint中Per-method :Setup與Teardown
[SetUp] //用于測試環(huán)境的建立
public void MySetup() {
    //do something.
}

[TearDown]  //清除測試環(huán)境
public void MyTeardown() {
     //do something.
}
  在每個[Test]方法之前,都會調(diào)用[SetUp]方法;并在每個[Test]方法完成之后,都會調(diào)用[TearDown]方法。

  11.NUint中的Per-class:TestFixtureSetUp和TestFixtureTearDown
  這兩個方法對整個Test Class設置一些環(huán)境,及所有測試方法都執(zhí)行完后做一些清理工作。
  當?shù)谝粋[Test]方法運行前,會調(diào)用[TestFixtureSetUp]方法,當所有[Test]方法都執(zhí)行后,會調(diào)用[TestFixtureTearDown]方法。

12.測試預期的異常
//如測試是否拋出ArgumentException
[Test, ExpectedException(typeof(ArgumentException))]
public void TestForException()
{
    Do.GetSomething(null);
    //Shouldn's get to here;
}

若測試方法預期地拋出ArgumentException異常,測試將會通過;若沒有拋出異常,則測試將會失敗。
一旦異常拋出了,測試方法中剩余的代碼都不會被執(zhí)行。

13. 忽略指定的測試方法
[Test, Ignore("Not run this method")]
public void TestMethod()
{
         //do something
}

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd