script.aculo.us單元測試,久違的綠色快感

這裏的綠色快感就是單元測試中的“祖國山河一片綠”的快感。

試着使用jsunit,什麼反應都沒有(對不起,我喜歡直接打開)。.翻閱<ajax design="" patterns="">中的test一章,才發現script.aculo.us中的單元測試支持相當簡單好用。

這裏直接把這本書裏面的單元測試代碼拿出來吧,其實就是script.aculo.us中的測試代碼。
</ajax>
xml 代碼
 
  1. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">    
  2. <head>       
  3. <title>Queue Test<!--</span-->>       
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" />       
  5. <script src="/run/Lib/js/util.js" type="text/javascript"></script> //util庫,非必需      
  6. <script src="prototype.js" type="text/javascript"></script> //是否需要不知,反正基本上都會用prototye       
  7. <script src="unittest.js" type="text/javascript"></script>  //單元測試的庫      
  8. <script src="queue.js" type="text/javascript"></script> //需要測試的代碼        
  9. <link rel="stylesheet" href="test.css" type="text/css" /> //綠色的來源        
  10. </head>       
  11. <body>       
  12.    ...       
  13.   <!-- Log output -->       
  14.    <div id="testlog"></div> //看的懂英文吧,單元測試的輸出在這裏      
  15.    <!-- Tests follow --> //下面就是測試使用的代碼了      
  16.   <script type="text/javascript" language="javascript" charset="utf-8">       
  17.      new Test.Unit.Runner({  //好像就是TestRunner      
  18.        q: null, //你寫TestCase也要定義field的      
  19.        setup: function( ) { with(this) { //相當於setUp()      
  20.          q = new Queue( );       
  21.        }},       
  22.        testEmptyQueue: function( ) { with(this) { //相當於testXXX()      
  23.          assertEqual(0, q.size);       
  24.         var items = q.items( );       
  25.         assertEqual(0, items.length);       
  26.  }},       
  27.    ...       
  28.  });       
  29. </script>    
  30. <!-- 下面可以有內容,模擬真實網頁中的內容 -->        
  31. </body>       
  32. </html>      


最終效果見ajaxify.com/run/reader/queueTest.html


7 tests, 34 assertions, 0 failures, 0 errors
Status Test Message
passed testEmptyQueue 2 assertions, 0 failures, 0 errors
passed testAdmit 2 assertions, 0 failures, 0 errors
passed testServe 3 assertions, 0 failures, 0 errors
passed testSeveral 10 assertions, 0 failures, 0 errors
passed testSequence 12 assertions, 0 failures, 0 errors
passed testServeEmptyQueueReturnsNull 2 assertions, 0 failures, 0 errors
passed testListener 3 assertions, 0 failures, 0 errors

久違的綠色快感又回來了!
發佈了0 篇原創文章 · 獲贊 0 · 訪問量 1268
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章