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

          主站蜘蛛池模板: 舞阳县| 长泰县| 甘德县| 延津县| 灵山县| 资讯 | 胶州市| 靖州| 晋江市| 筠连县| 牡丹江市| 泾源县| 溧阳市| 汪清县| 五寨县| 南通市| 宁海县| 河曲县| 汶川县| 增城市| 福鼎市| 曲阳县| 阿瓦提县| 曲周县| 留坝县| 鹤峰县| 土默特右旗| 新昌县| 理塘县| 吴桥县| 德化县| 昌都县| 阿荣旗| 界首市| 谢通门县| 南涧| 汽车| 阿克| 沙雅县| 华池县| 台中市|