<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 15.5.?小結 單元測試是一個強大的概念,使用得當的話既可以減少維護成本又可以增加長期項目的靈活性。同樣重要的是要意識到單元測試并不是“靈丹妙藥”,也不是“銀彈”。編寫好的測試用例很困難,保持其更新更需要磨練 (特別是當顧客對修復嚴重的 Bug 大呼小叫之時)。單元測試不是其它形式測試的替代品,比如說功能性測試、集成測試以及可用性測試。但它切實可行且功效明顯,一旦相識,你會反問為什么以往沒有應用它。 這一章涵蓋了很多內容,有很多都不是 Python 所特有的。很多語言都有單元測試框架,都要求你理解相同的基本概念: * 測試用例的設計方針是目的單一、可以自動運行、互不干擾。 * 在被測試代碼編寫_之前_ 編寫測試用例。 * 編寫測試[有效輸入的測試用例](../unit_testing/testing_for_success.html "13.4.?正面測試 (Testing for success)")并檢查正確的結果。 * 編寫測試[無效輸入的測試用例](../unit_testing/testing_for_failure.html "13.5.?負面測試 (Testing for failure)")并檢查正確的失敗。 * 為[描述 Bug](index.html#roman.bugs "15.1.?處理 bugs") 或[反映新需求](handling_changing_requirements.html "15.2.?應對需求變化")而編寫和升級測試用例。 * 為改進性能、可伸縮性、可讀性、可維護性和任何缺少的特性而無情地[重構](refactoring.html "15.3.?重構")。 另外,你應該能夠自如地做到如下 Python 的特有工作: * 繼承 [`unittest.TestCase`](../unit_testing/testing_for_success.html#roman.testtoromanknownvalues.example "例?13.2.?testToRomanKnownValues") 生成子類并為每個單獨的測試用例編寫方法。 * 使用 [`assertEqual`](../unit_testing/testing_for_success.html#roman.testtoromanknownvalues.example "例?13.2.?testToRomanKnownValues") 檢查已知結果的返回。 * 使用 [`assertRaises`](../unit_testing/testing_for_failure.html#roman.tobadinput.example "例?13.3.?測試 toRoman 的無效輸入") 檢查函數是否引發已知異常。 * 在 `if __name__` 子句中調用 [`unittest.main()`](../unit_testing/stage_1.html#roman.stage1.output "例?14.2.?以 romantest1.py 測試 roman1.py 的輸出") 來一次性運行所有測試用例。 * 以[詳細 (verbose)](../unit_testing/stage_1.html#roman.stage1.output "例?14.2.?以 romantest1.py 測試 roman1.py 的輸出") 或者[普通 (regular)](refactoring.html#roman.stage8.1.output "例?15.12.?用 romantest81.py 測試 roman81.py 的結果") 模式運行單元測試 ## 進一步閱讀 * XProgramming.com 有多種語言的 [單元測試框架](http://www.xprogramming.com/software.htm) 的下載鏈接。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看