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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                #### 1.3 測試函數、用例和套件(2) 到目前為止,這些測試都很清晰簡單,每個測試都只用了一個斷言。現在,上面的測試用例把所有的測試都組合進了一個對象,但是,由于這個date對象還是在外部創建的,所以這讓事情看起來不太自然,因為它似乎應該是測試的一部分。當然,我們確實可以在每個測試中都創建一個對象,但因為創建這些對象的方式完全相同,所以這樣就等于重復做了很多遍同樣的事情,而這并不是必要的。所以,更好的選擇是把通用的設置代碼都放在一個單獨的地方。 Setup和Teardown 在xUnit框架里通常會提供setUp(設置)和tearDown(拆除)方法,用來集中設置并提供測試數據,也叫測試配件文件,所以,它們通常會在每個測試之前和之后分別調用。下面,讓我們用SetUp方法把date對象加進來作為一個測試配件文件。正如清單1.12顯示的,更改過的testCase函數檢查測試用例是否有setUp和tearDown,如果有的話,在適當的時候運行它們。 清單1.12 在testCase里實現setUp和tearDown ~~~ function testCase(name,tests){ assert.count =0; var successful =0; var testCount =0; var hasSetup =typeof tests.setUp =="function"; var hasTeardown =typeof tests.tearDown =="function"; for (var test in tests){ if (!/^test/.test(test)){ continue; } testCount++; try { if (hasSetup){ tests.setUp(); } tests [test ](); output(test,"#0c0"); if (hasTeardown){ tests.tearDown(); } //If the tearDown method throws an error,it is //considered a test failure,so we don't count //success until all methods have run successfully successful++; } catch (e){ output(test +"failed:"+e.message,"#c00"); } } var color =successful ==testCount ?"#0c0":"#c00"; output("<strong>"+testCount +"tests,"+ (testCount -successful)+"failures</strong>", color); } ~~~ 用新加的setUp方法,我們可以增加一個對象屬性來存放測試配件文件,如清單1.13所示。 清單1.13 在strftime測試用例中使用setUp ~~~ testCase("strftime test",{ setUp:function (){ this.date =new Date(2009,9,2,22,14,45); }, "test format specifier Y":function (){ assert("%Y should return full year", this.date.strftime("%Y")==2009); }, //... }); ~~~
                  <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>

                              哎呀哎呀视频在线观看