2006-12-15
script.aculo.us单元测试,久违的绿色快感
这里的绿色快感就是单元测试中的“祖国山河一片绿”的快感。
试着使用jsunit,什么反应都没有(对不起,我喜欢直接打开)。.翻阅中的test一章,才发现script.aculo.us中的单元测试支持相当简单好用。
这里直接把这本书里面的单元测试代码拿出来吧,其实就是script.aculo.us中的测试代码。
最终效果见ajaxify.com/run/reader/queueTest.html
久违的绿色快感又回来了!
试着使用jsunit,什么反应都没有(对不起,我喜欢直接打开)。.翻阅
这里直接把这本书里面的单元测试代码拿出来吧,其实就是script.aculo.us中的测试代码。
xml 代码
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Queue Test<!--</span-->>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script src="/run/Lib/js/util.js" type="text/javascript"></script> //util库,非必需
- <script src="prototype.js" type="text/javascript"></script> //是否需要不知,反正基本上都会用prototye
- <script src="unittest.js" type="text/javascript"></script> //单元测试的库
- <script src="queue.js" type="text/javascript"></script> //需要测试的代码
- <link rel="stylesheet" href="test.css" type="text/css" /> //绿色的来源
- </head>
- <body>
- ...
- <!-- Log output -->
- <div id="testlog"></div> //看的懂英文吧,单元测试的输出在这里
- <!-- Tests follow --> //下面就是测试使用的代码了
- <script type="text/javascript" language="javascript" charset="utf-8">
- new Test.Unit.Runner({ //好像就是TestRunner
- q: null, //你写TestCase也要定义field的
- setup: function( ) { with(this) { //相当于setUp()
- q = new Queue( );
- }},
- testEmptyQueue: function( ) { with(this) { //相当于testXXX()
- assertEqual(0, q.size);
- var items = q.items( );
- assertEqual(0, items.length);
- }},
- ...
- });
- </script>
- <!-- 下面可以有内容,模拟真实网页中的内容 -->
- </body>
- </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 |
久违的绿色快感又回来了!
- 浏览: 64280 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
使用ActiveMerchant支持支 ...
还有人这样用过吗?
-- by boyjunqiang -
谷歌音乐,很百度
chris_in 写道我喜欢hitfm,lastfm不好用 同道中人,天天听~
-- by satellite -
谷歌音乐,很百度
庄表伟 写道 www.8box.com 我更推荐这个 这个.真的不错.终于 ...
-- by lsk -
谷歌音乐,很百度
http://www.yobo.com/這個也不錯
-- by huhuGang -
谷歌音乐,很百度
chris_in 写道我喜欢hitfm,lastfm不好用呵呵,hitfm是电台 ...
-- by 花花公子






评论排行榜