■インストール ダウンロード mv JsTestDriver-1.3.5.jar /home/yuji/prog/jsTestDriver cd /home/yuji/prog/jsTestDriver mkdir src mkdir src-test vi jsTestDriver.conf ---------- server: http://localhost:9876 load: - src/*.js test: - src-test/*.js ---------- ■テストコード vi src-test/greetertest.js ---------- GreeterTest = TestCase("GreeterTest"); GreeterTest.prototype.testGreet = function() { var greeter = new myapp.Greeter(); assertEquals("Hello World!", greeter.greet("World")); }; ---------- ■ソースコード vi src/greeter.js ---------- myapp = {}; myapp.Greeter = function() { }; myapp.Greeter.prototype.greet = function(name) { return "Welcome! " + name + "!"; }; ---------- ■テスト実行 java -jar JsTestDriver-1.3.5.jar --port 9876 #java -jar JsTestDriver-1.3.5.jar --port 9876 --browser /opt/google/chrome/google-chrome http://localhost:9876 「Capture This Browser」クリック java -jar JsTestDriver-1.3.5.jar --tests all ■Eclipseプラグイン http://js-test-driver.googlecode.com/svn/update/ すべてチェック うまくいかない ----------------------------------------- https://qunitjs.com/ ■ダウンロード qunit-1.14.0.css" qunit-1.14.0.js" ■テストケース vi src/tests.js ---------- module("syncTest"); test("syncFuncTest", 1, function(){ equal("hello, world!", syncFunc(), "return to expected data"); }); module("async"); test("asyncFuncTest", function(){ expect(2); stop(); asyncFunc(function(message){ start(); ok(true, "call to callback function"); equal("hello, world!", message, "return to expected data"); }); }); ---------- ■テスト対象 vi src/target.js ---------- function syncFunc(){ return "hello!"; } function asyncFunc(callback){ setTimeout(function(){ callback("world!"); }, 500); } ---------- ■テスト対象、ケースの読み込み(ブラウザで開く) vi index.html ---------- QUnit Example
---------- ----------------------------------------- Crossfire http://another.maple4ever.net/archives/1852/ ■Firebug Firebugインストール Firebugで一度「スクリプト読み込み」しておく Firebugですべてのタブを有効化 FIrefoxの表示 -> ツールバー -> アドオンバーを表示して、右下のアイコンからスタート ■Crossfire Crossfireの.xpiインストール https://github.com/mrennie/crossfire 右下のアイコンからスタート「Start Server」(ポート5000) ■eclipse Debug Configurations Remote JavaScriptダブルクリック connector: CrossFire - Remote Attach ----------------------------------------- Js Debug ■インストール http://jsdt.googlecode.com/svn/trunk/org.ayound.js.debug.update index.htmlを選択 Debug Configurations javascript Debug url:file:///home/yuji/prog/workspaces/JavaScript/workspace/TestJavaScript/index.html browser: /opt/google/chrome/google-chrome ----------------------------------------- http://codezine.jp/article/detail/7367 ■mocha.js, mocha.css cd /home/yuji/prog/workspaces/JavaScript git clone git@github.com:visionmedia/mocha.git mocha.js, mocha.cssをコピー ■chai.js http://chaijs.com/chai.js ■ソースコード vi mochatarget.js ---------- //テスト対象のメソッド var fizzbuzz = function(n) { if (n % 3 === 0 && n % 5 === 0) return "Fizz,Buzz"; else if (n % 3 === 0) return "Fizz"; else if (n % 5 === 0) return "Buzz"; else return n; } ---------- ■テストコード vi mochatest.js ---------- suite('#fizzbuzz()', function() { test("3の場合はFizzが返ってくる", function() { assert.equal("Fizz", fizzbuzz(3), '3の場合はFizzが返ってくる'); }); test("5の場合はBuzzが返ってくる", function() { assert.equal("Buzz", fizzbuzz(5), '3の場合はFizzが返ってくる'); }); test("15の場合はFizz,Buzzが返ってくる", function() { assert.equal("Fizz,Buzz", fizzbuzz(15), '3の場合はFizzが返ってくる'); }); test("3と5の倍数以外は、数字が返ってくる", function() { assert.notEqual("Fizz", fizzbuzz(1), '1の場合はFizzが返ってこない'); assert.notEqual("Buzz", fizzbuzz(1), '1の場合はBuzzが返ってこない'); assert.equal("1", fizzbuzz(1), '1の場合は数字がそのまま返ってくる'); assert.equal("7", fizzbuzz(7), '7の場合は数字がそのまま返ってくる'); assert.equal("13", fizzbuzz(13), '13の場合は数字がそのまま返ってくる'); }); }); ---------- ■html vi mochatdd.html ----------
---------- ----------------------------------------- http://sinonjs.org/ http://dev.classmethod.jp/etc/javascript_testing_framework_sinonjs-1/ sinon-1.9.0.js ----------------------------------------- http://www.sonarqube.org/downloads/ sonar-3.7.4.zip cd /home/yuji/prog/sonar-3.7.4/ ■Java export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 ■maven export M3_HOME=/home/yuji/prog/apache-maven-3.2.1 #M3=$M3_HOME/bin M3=$M3_HOME export PATH=$M3:$PATH ■起動 cd /home/yuji/prog/sonar-3.7.4/bin/linux-x86-64 ./sonar.sh start & ■メトリクス情報登録(mavenプロジェクトで) mvn clean sonar:sonar ■表示 http://localhost:9000/ ----------------------------------------- sudo apt-get install sikuli-ide sikuli-ide &