Node.js テストコード
テスティングフレームワーク
mocha
express作者が開発しているテスティングフレームワーク
ConnectやSails.jsでも使用されている。
Wikiに記載の情報は要確認。(特にsinon.js)
ブラウザでの使用にも対応している。
「--watch(-w) --reporter(-R) min」の組み合わせは、TDDやBDDで便利そう!
-g [pattern]: 実行対象のテストをパターンで絞れる
Jasmine
behavior-driven development framework
Node.jsでは、「jasmine-node」を使用する。
(JasmineのGitHub Wikiからリンクされていたので、信頼できるようだ。)
Nodeunit
Easy unit testing in node.js and the browser, based on the assert module.
その他
Yadda, Cucumber.js, and so on
アサーションライブラリ
Node.jsでは、assertモジュールが提供されているが、その他のスタイルを提供するNPMもある。
should.js
BDD style assertions for node.js
欠点 対象の変数が、nullやundefinedの時は、オブジェクトではないので、
shouldを呼ぶと、エラーになってしまう。
expect.js
Minimalistic BDD-style assertions for Node.JS and the browser.
should.jsをベースに作られたらしい。
Chai
BDD / TDD assertion library for node and the browser
better-assert
Better c-style assertions using callsite for self-documenting failure messages.
expectations
Jasmine-style expect syntax for nodejs + browser
まとめ
とりあえず、ConnectやExpress,Sails.jsで使われている「mocha」と「should.js」を習得する。