weidagang2046的專欄

          物格而后知致
          隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
          數據加載中……

          體驗Vs2005 beta2 測試工具

          在Vs2005中加入了單元測試工具,使用與NUnit差不多。但功能更加豐富了,而且使用更加方便,有利于項目的協調工作。而且還支持調試測試,(不知道NUnit支不支持,我是沒用過。)方便我們調試出錯代碼。
          ??? Vs2005 Test tool 與NUnit 特性類對應
          ????????????NUnit????????????????????????????????????????????????Vs2005 Tools
          ???? NUnit.Framework???????????
          Microsoft.VisualStudio.QualityTools.UnitTesting.Framework
          ???? TestFixtureAttribute???????????????????
          TestClassAttribute
          ??? TestFixtureSetUpAttribute???????????
          ClassInitializeAttribute
          ??? TestFixtureTearDownAttribute???????
          ClassCleanupAttribute
          ??? SetUpAttribute??????????????????????????????? TestInitializeAttribute???
          ???? TearDownAttribute???????????????????????
          TestCleanupAttribute
          ????
          ??? 創建一個測試工程。
          ??? 打開UnitTest1.cs? 它已經為我們生成了一個測試的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的一眼就會明白那些Attribute是干嘛用的了。在里面寫了一句簡單的斷言語句。這樣就是一個簡單的測試實例了。
          ??? 接下來運行這個測試實例。找到Test菜單項,選擇"Manage and Execute Tests。在這管理器里面可以選擇在項目中已經存在的測試實例。并選擇是否運行測試。

          ?
          ??? 單擊"By Test List"右邊那上工具欄按鈕。就開始執行測試了。查看測試結果
          雙擊可以看到詳細信息。
          ??? 剛才說到的還可以斷點調試。很簡單,只需要在測試實例設置斷點,然后點擊剛才的運行按扭的下拉框,可以看到有“Debug Checked tests”。這樣就可以調試了。很方便!

          ??? 就這么簡單!

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

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

          主站蜘蛛池模板: 濮阳县| 荆州市| 洛宁县| 昂仁县| 饶阳县| 会东县| 阜南县| 林周县| 石嘴山市| 县级市| 老河口市| 广水市| 新邵县| 竹溪县| 昌乐县| 江山市| 汉川市| 舞钢市| 新蔡县| 霍山县| 元江| 龙川县| 通辽市| 敖汉旗| 广河县| 仁布县| 沛县| 文昌市| 太保市| 武宣县| 客服| 奉新县| 英吉沙县| 柳江县| 怀宁县| 枣阳市| 麟游县| 萨迦县| 昌吉市| 乌兰县| 密云县|