Riot.js 快速的JavaScript單元測(cè)試框架
更新時(shí)間:2009年11月09日 19:11:10 作者:
Riot是一個(gè)快速,富有表現(xiàn)力,上下文驅(qū)動(dòng) 的單元測(cè)試框架。最初是用于Ruby的單元測(cè)試,最近作者Alex Young又實(shí)現(xiàn)了Riot的JavaScript版- Riot.js。
http://github.com/alexyoung/riotjs
示例:
Ruby代碼
context "a new user" do
setup { User.new }
asserts("that it is not yet created") { topic.new_record? }
end
context "a new user" do
setup { User.new }
asserts("that it is not yet created") { topic.new_record? }
end
Javascript代碼
Riot.run(function() {
context('basic riot functionality', function() {
given('some simple equality tests', function() {
asserts('a simple truth test should return true', true).isTrue();
asserts('isNull is null', null).isNull();
});
given('another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});
given('a context concerned with functions', function() {
asserts('asserts() should allow functions to be compared', function() {
return 'test string';
}).equals('test string');
});
});
given('yet another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});
});
示例:
Ruby代碼
復(fù)制代碼 代碼如下:
context "a new user" do
setup { User.new }
asserts("that it is not yet created") { topic.new_record? }
end
context "a new user" do
setup { User.new }
asserts("that it is not yet created") { topic.new_record? }
end
Javascript代碼
復(fù)制代碼 代碼如下:
Riot.run(function() {
context('basic riot functionality', function() {
given('some simple equality tests', function() {
asserts('a simple truth test should return true', true).isTrue();
asserts('isNull is null', null).isNull();
});
given('another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});
given('a context concerned with functions', function() {
asserts('asserts() should allow functions to be compared', function() {
return 'test string';
}).equals('test string');
});
});
given('yet another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});
});
相關(guān)文章
JavaScript 設(shè)計(jì)模式學(xué)習(xí) Singleton
JavaScript設(shè)計(jì)模式學(xué)習(xí) Singleton2009-07-07
javascript面向?qū)ο缶幊?一) 實(shí)例代碼
javascript面向?qū)ο缶幊虒?shí)例代碼,代碼也算比較基礎(chǔ)了,不懂得朋友可以參考腳本之家之前發(fā)布的文章。2010-06-06
用JavaScript實(shí)現(xiàn)單繼承和多繼承的簡(jiǎn)單方法
JavaScript是一種強(qiáng)大的多泛型編程語(yǔ)言,其融合了面向過(guò)程、面向?qū)ο蠛秃瘮?shù)式編程于一身,具備強(qiáng)大的表現(xiàn)能力。2009-03-03
javascript 對(duì)象定義方法 簡(jiǎn)單易學(xué)
工廠模式 初級(jí)開(kāi)發(fā)者可能會(huì)這樣定義對(duì)象2009-03-03
javascript 面向?qū)ο?實(shí)現(xiàn)namespace,class,繼承,重載
這幾天老大天天嚷嚷要重構(gòu)我們寫的javascript,抱怨代碼太混亂,可讀性差,維護(hù)困難,要求javascript也按面對(duì)象的模型來(lái)重構(gòu)。2009-10-10
javascript 面向?qū)ο缶幊袒A(chǔ) 多態(tài)
javascript 面向?qū)ο缶幊袒A(chǔ) 多態(tài) 的實(shí)現(xiàn)方法說(shuō)明,大家可以看下下面的代碼。2009-08-08
JavaScript定義類或函數(shù)的幾種方式小結(jié)
js中不論是定義類或者函數(shù),很多朋友想將代碼寫的更專業(yè),更方便擴(kuò)展等,那么就可以參考這篇文章了,最好是總結(jié),建議大家收藏下。2011-01-01

