Riot.js 快速的JavaScript單元測試框架
更新時間:2009年11月09日 19:11:10 作者:
Riot是一個快速,富有表現(xiàn)力,上下文驅動 的單元測試框架。最初是用于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');
});
});
相關文章
javascript中的對象創(chuàng)建 實例附注釋
為了讓你的js代碼更加的專業(yè)與代碼的條理性,很多情況下都是定義成對象的方式來書寫代碼,想深入的朋友可以參考下。2011-02-02