Riot.js 快速的JavaScript單元測試框架
更新時間:2009年11月09日 19:11:10 作者:
Riot是一個快速,富有表現(xiàn)力,上下文驅(qū)動 的單元測試框架。最初是用于Ruby的單元測試,最近作者Alex Young又實現(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代碼
復制代碼 代碼如下:
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');
});
});
相關(guān)文章
JavaScript 設(shè)計模式學習 Singleton
JavaScript設(shè)計模式學習 Singleton2009-07-07
用JavaScript實現(xiàn)單繼承和多繼承的簡單方法
JavaScript是一種強大的多泛型編程語言,其融合了面向過程、面向?qū)ο蠛秃瘮?shù)式編程于一身,具備強大的表現(xiàn)能力。2009-03-03
javascript 面向?qū)ο?實現(xiàn)namespace,class,繼承,重載
這幾天老大天天嚷嚷要重構(gòu)我們寫的javascript,抱怨代碼太混亂,可讀性差,維護困難,要求javascript也按面對象的模型來重構(gòu)。2009-10-10
javascript 面向?qū)ο缶幊袒A(chǔ) 多態(tài)
javascript 面向?qū)ο缶幊袒A(chǔ) 多態(tài) 的實現(xiàn)方法說明,大家可以看下下面的代碼。2009-08-08
JavaScript定義類或函數(shù)的幾種方式小結(jié)
js中不論是定義類或者函數(shù),很多朋友想將代碼寫的更專業(yè),更方便擴展等,那么就可以參考這篇文章了,最好是總結(jié),建議大家收藏下。2011-01-01

