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

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

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

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

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

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

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

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

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