<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 第 9 章?測試替身 Gerard Meszaros 在 [[Meszaros2007]](# "xUnit Test Patterns: Refactoring Test Code") 中介紹了測試替身的概念: > 有時候對被測系統(SUT)進行測試是很困難的,因為它依賴于其他無法在測試環境中使用的組件。這有可能是因為這些組件不可用,它們不會返回測試所需要的結果,或者執行它們會有不良副作用。在其他情況下,我們的測試策略要求對被測系統的內部行為有更多控制或更多可見性。 > 如果在編寫測試時無法使用(或選擇不使用)實際的依賴組件(DOC),可以用測試替身來代替。測試替身不需要和真正的依賴組件有完全一樣的的行為方式;他只需要提供和真正的組件同樣的 API 即可,這樣被測系統就會以為它是真正的組件! > --Gerard Meszaros PHPUnit 提供的 `getMockBuilder($type)` 方法可以在測試中用來自動生成對象,此對象可以充當任意指定原版類型(接口或類名)的測試替身。在任何預期或要求使用原版類的實例對象的上下文中都可以使用這個測試替身對象來代替。 在默認情況下,原版類的所有方法都會被替換為只會返回 `null` 的偽實現(其中不會調用原版方法)。使用諸如 `will($this->returnValue())` 之類的方法可以對這些偽實現在被調用時應當返回什么值做出配置。 ### 局限性:final、private、與 static 方法 請注意,`final`、`private` 和 `static` 方法無法對其進行上樁(stub)或模仿(mock)。PHPUnit 的測試替身功能將會忽略它們,并維持它們的原始行為。 ### 警告 請關注一下這個事實:參數管理方式已經修改過了。在之前的實現中,將會克隆對象的所有參數。這樣就無法檢查傳遞給方法的是否是同一個對象。[Example?9.15, “測試某個方法將會被調用一次,并且以某個特定對象作為參數。”](# "Example?9.15.?測試某個方法將會被調用一次,并且以某個特定對象作為參數。") 展示了新的實現方式在什么情況下會非常有用。[Example?9.16, “創建仿件對象時啟用參數克隆”](# "Example?9.16.?創建仿件對象時啟用參數克隆")展示了如何切換回之前的行為方式。
                  <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>

                              哎呀哎呀视频在线观看