weidagang2046的專欄

          物格而后知致
          隨筆 - 8, 文章 - 409, 評(píng)論 - 101, 引用 - 0
          數(shù)據(jù)加載中……

          體驗(yàn)Vs2005 beta2 測(cè)試工具

          在Vs2005中加入了單元測(cè)試工具,使用與NUnit差不多。但功能更加豐富了,而且使用更加方便,有利于項(xiàng)目的協(xié)調(diào)工作。而且還支持調(diào)試測(cè)試,(不知道NUnit支不支持,我是沒(méi)用過(guò)。)方便我們調(diào)試出錯(cuò)代碼。
          ??? Vs2005 Test tool 與NUnit 特性類對(duì)應(yīng)
          ????????????NUnit????????????????????????????????????????????????Vs2005 Tools
          ???? NUnit.Framework???????????
          Microsoft.VisualStudio.QualityTools.UnitTesting.Framework
          ???? TestFixtureAttribute???????????????????
          TestClassAttribute
          ??? TestFixtureSetUpAttribute???????????
          ClassInitializeAttribute
          ??? TestFixtureTearDownAttribute???????
          ClassCleanupAttribute
          ??? SetUpAttribute??????????????????????????????? TestInitializeAttribute???
          ???? TearDownAttribute???????????????????????
          TestCleanupAttribute
          ????
          ??? 創(chuàng)建一個(gè)測(cè)試工程。
          ??? 打開(kāi)UnitTest1.cs? 它已經(jīng)為我們生成了一個(gè)測(cè)試的Sample框架了.
          [TestClass]
          ????
          public ? class
          ?UnitTest1
          ????
          {
          ????????
          public
          ?UnitTest1()
          ??????
          {
          ????????????
          //

          ????????????
          // ?TODO:?Add?constructor?logic?here
          ????????????
          //
          ????????}


          ????????
          /// ? <summary>
          ????????
          /// ?Initialize()?is?called?once?during?test?execution?before
          ????????
          ///
          ?test?methods?in?this?test?class?are?executed.
          ????????
          /// ? </summary>

          ????????[TestInitialize()]
          ????????
          public ? void
          ?Initialize()
          ??????
          {
          ????????????
          // ??TODO:?Add?test?initialization?code

          ????????}


          ????????
          /// ? <summary>
          ????????
          /// ?Cleanup()?is?called?once?during?test?execution?after
          ????????
          ///
          ?test?methods?in?this?class?have?executed?unless?the
          ????????
          ///
          ?corresponding?Initialize()?call?threw?an?exception.
          ????????
          /// ? </summary>

          ????????[TestCleanup()]
          ????????
          public ? void
          ?Cleanup()
          ??????
          {
          ????????????
          // ??TODO:?Add?test?cleanup?code

          ????????}


          ????????[TestMethod]
          ????????
          public ? void ?TestMethod1()
          ??????
          {
          ????????????Assert.IsTrue(
          true , " this?is?work "
          );
          ????????}

          ????}

          ??? 熟悉NUnit的一眼就會(huì)明白那些Attribute是干嘛用的了。在里面寫(xiě)了一句簡(jiǎn)單的斷言語(yǔ)句。這樣就是一個(gè)簡(jiǎn)單的測(cè)試實(shí)例了。
          ??? 接下來(lái)運(yùn)行這個(gè)測(cè)試實(shí)例。找到Test菜單項(xiàng),選擇"Manage and Execute Tests。在這管理器里面可以選擇在項(xiàng)目中已經(jīng)存在的測(cè)試實(shí)例。并選擇是否運(yùn)行測(cè)試。

          ?
          ??? 單擊"By Test List"右邊那上工具欄按鈕。就開(kāi)始執(zhí)行測(cè)試了。查看測(cè)試結(jié)果
          雙擊可以看到詳細(xì)信息。
          ??? 剛才說(shuō)到的還可以斷點(diǎn)調(diào)試。很簡(jiǎn)單,只需要在測(cè)試實(shí)例設(shè)置斷點(diǎn),然后點(diǎn)擊剛才的運(yùn)行按扭的下拉框,可以看到有“Debug Checked tests”。這樣就可以調(diào)試了。很方便!

          ??? 就這么簡(jiǎn)單!

          from:
          http://www.cnblogs.com/hjf1223/archive/2005/09/22/241757.aspx

          posted on 2007-01-03 17:28 weidagang2046 閱讀(409) 評(píng)論(0)  編輯  收藏 所屬分類: Windows

          主站蜘蛛池模板: 江津市| 天津市| 梧州市| 东辽县| 泌阳县| 隆化县| 江油市| 盱眙县| 尼玛县| 东辽县| 河源市| 明星| 大同县| 横峰县| 梧州市| 綦江县| 灌阳县| 平乐县| 新蔡县| 茌平县| 潜山县| 泰兴市| 河北区| 越西县| 罗田县| 新泰市| 平定县| 镇原县| 蒙阴县| 襄垣县| 珠海市| 望奎县| 祁连县| 当涂县| 中卫市| 河北区| 长汀县| 北流市| 临漳县| 丽水市| 奉贤区|