Shibuya.js テクニカルトーク Test.jsã§id:t-wadaããã®è©±ãã¨ã¦ãèå³æ·±ãã
js テスト放浪記
qunit-tapã¨ããã®ãé
åçã«æããã®ã§node.jsã®ãã¹ãã§ä½¿ã£ã¦ã¿ã¾ããã
GitHub - twada/qunit-tap: A TAP Output Producer Plugin for QUnit
quinit-tapã¨ã¯
ã¾ãQUnitã«ã¤ãã¦ã
QUnit
QUnitèªä½ã¯å
¨ç¶ä½¿ã£ããã¨ãªãã¦è©³ããã¯ç¥ããªãã®ã§ããããã¨ãã¨jQueryã®ãã¹ãç¨ã«ä½ããããã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ã§ãä»ã¯jQueryã«é¢ä¿ãªãè²ã
ãªå ´é¢ã§ã®JavaScriptã®ãã¹ãã«ä½¿ããããã«ãªã£ã¦ãããã¨ã®ãã¨ã
QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery project to test its code and plugins but is capable of testing any generic JavaScript code (and even capable of testing JavaScript code on the server-side).
node.jsç¨ã«ãnode-qunitã¨ããã®ããã£ã¦ã³ãã³ãã©ã¤ã³ã§QUnitçãªãã¹ããè¡ãã¢ã¸ã¥ã¼ã«ãããã®ã ãã©ãqunit-tapã¯ããã¨ã¯é¢ä¿ãªãQUnitã®åºåå½¢å¼ãTAPå½¢å¼ã«æãããã¨ããç®çã§ä½ããã¦ãã¾ããTAPåºåã«ã¤ãã¦ã¯è¥å¹²å¤ããããããªããã©ä¸è¨URLãªã©ãåç
§ã
404 Blog Not Found:「同じコード」の同じって何さ - TAPのススメ
第1回 Perlにおけるテストの概要/TAPとは?:Happy Testing Perl|gihyo.jp … 技術評論社
TAPå½¢å¼ã ã¨ä½ãå¬ãããã¨ããã¨ãPerlã®Test::Harnessã¢ã¸ã¥ã¼ã«ã«ä»å±ããproveã³ãã³ãã§ãã¹ãå®è¡æ¹æ³ãåºåãã«ã¹ã¿ãã¤ãºã§ããã®ã§ãã
http://search.cpan.org/~andya/Test-Harness-3.23/bin/prove
ä¾ãã°ãstateãä¿åãã¦åå失æãããã¹ãã ãã次åå®è¡ããããã«ãããã¨ã
proveをうまく使ってテスト実行を効率化しよう - JPerl Advent Calendar 2010 Casual Track
è¤æ°ã®ãã¹ãã並åã§èµ°ãããããPluginãæ¸ãã°çµäºå¾ã«çµæãGrowléç¥ããã¦ããããã¨ããã§ãã¾ãã
ã¤ã³ã¹ãã¼ã«
2010/03/25æç¹ã§ã®ææ°çã¯0.9.8ãnpmã§ç°¡åã«å ¥ãã¾ãã
$ npm install qunit-tap npm info it worked if it ends with ok npm info using [email protected] npm info using [email protected] npm info preinstall [email protected] npm info install [email protected] npm info postinstall [email protected] npm info preactivate [email protected] npm info activate [email protected] npm info postactivate [email protected] npm info build Success: [email protected] npm ok
ãã¹ãã®æºåããã
qunit-tapèªä½ã¯åºåãæ´ããå½¹ç®ãããã ããªã®ã§ãQUnitæ¬ä½ã¯å¥éæã£ã¦ããå¿ è¦ãããã¾ã(qunit-tapã®npmããã±ã¼ã¸ã«ãå«ã¾ãã¦ããããã©)ã
$ mkdir myproject $ cd myproject $ mkdir deps $ git clone git://github.com/jquery/qunit.git deps $ ls deps/ README.md package.json qunit test
ã§ãqunit-tapã使ãè¨å®ããããã«ãã¼ã¹ã¯ãªãã(test_helper.js)ãç¨æãã¾ãã
exports = module.exports = global; QUnit = require("./deps/qunit/qunit").QUnit; var qunitTap = require("qunit-tap").qunitTap; qunitTap(QUnit, require("sys").puts, { noPlan: true }); QUnit.init(); exports.assert = QUnit;
nodeã§ä½¿ããªãããã ãã§ååã§ããcloneãã¦ããqunitãrequireãã¦ãããèªã¿è¾¼ã¾ããQUnitãªãã¸ã§ã¯ããæ¨æºåºåé¢æ°ããªãã·ã§ã³ããå¼æ°ã«æ¸¡ãã¦qunitTap()ãå¼ãã§ã諸ã
exportsã«å
¥ãã¦ããã¾ãã
ãã¹ããæ¸ã
æºåãã§ããã®ã§ãã¹ããæ¸ãã¦ã¿ã¾ããproveã³ãã³ãã¯ããã©ã«ãã§ã¯"t"ãã£ã¬ã¯ããªä»¥ä¸ã®ãã¡ã¤ã«ããã¹ã対象ã¨ãã¦æ¢ç´¢ããã®ã§ãä¸å¿./t以ä¸ã«ä½ãã¾ãã
require('../test_helper.js'); QUnit.test('hoge', function() { assert.ok(1); }); QUnit.start();
ä½æãããã¹ãã¯nodeã³ãã³ãã§å®è¡ãããã¨ã§ãã¹ããèµ°ãã¾ãã
$ mkdir t $ vi t/hoge.js $ ls deps t test_helper.js $ ls t/ hoge.js $ node t/hoge.js # test: hoge ok 1 1..1
ç¡äºã«ãã¹ããå®è¡ããã'ok'ã¨TAPå½¢å¼ã®ãã¹ãçµæãåºåããã¾ããã調åã«ä¹ã£ã¦ããä¸ã¤ãã¹ããä½ã£ã¦ã¿ã¾ãã
require('../test_helper.js'); QUnit.test('fuga', function() { assert.expect(2); assert.equal(1 + 23, 24, 'add'); assert.equal('fuga', 'fu' + 'ga', 'cat'); }); QUnit.test('piyo', function() { assert.expect(3); var a = []; assert.deepEqual(a, [], 'empty'); a.push('hoge'); assert.deepEqual(a, ['hoge'], 'pushed'); a.push({ key: 'value' }); assert.deepEqual(a, [ 'hoge', { key: 'value' } ], 'has Object'); }); QUnit.start();
$ node t/fuga.js # test: fuga ok 1 - add ok 2 - cat # test: piyo ok 3 - empty ok 4 - pushed ok 5 - has Object 1..5
ãã¾ãããã¾ããããã¹ããéããªãå ´åã¯ä¸è¨ä¾ã®ããã«"not ok"ãåºåããã¾ãã
$ node t/fuga.js # test: fuga not ok 1 - add, expected: 25 result: 24 ok 2 - cat # test: piyo ok 3 - empty ok 4 - pushed ok 5 - has Object 1..5
proveã³ãã³ãã使ã
ã㦠è¤æ°ã®ãã¹ããã¡ã¤ã«ãããã¨ãã¡ãã¡å®è¡ããã®ãé¢åã«ãªã£ã¦ãã¾ããããã§proveã³ãã³ãã®ç»å ´ã
ããã©ã«ãã§ã¯".t"ã®æ¡å¼µåãæã¤ãã¡ã¤ã«ãperlã§å®è¡ããããã«ãªã£ã¦ããã®ã§ããã®ã¸ãã¯ãªãã·ã§ã³ã§èª¿æ´ãã¦ããã¾ãã
$ prove --ext=.js --exec=node t/fuga.js .. ok t/hoge.js .. ok All tests successful. Files=2, Tests=6, 1 wallclock secs ( 0.03 usr 0.01 sys + 0.12 cusr 0.02 csys = 0.18 CPU) Result: PASS $ prove --ext=.js --exec=node -v t/fuga.js .. # test: fuga ok 1 - add ok 2 - cat # test: piyo ok 3 - empty ok 4 - pushed ok 5 - has Object 1..5 ok t/hoge.js .. # test: hoge ok 1 1..1 ok All tests successful. Files=2, Tests=6, 0 wallclock secs ( 0.03 usr 0.01 sys + 0.12 cusr 0.02 csys = 0.18 CPU) Result: PASS
ãããªãããã§ããã¹ã対象ãã¡ã¤ã«ãåæã«è¦ã¤ãåºãã¦å®è¡ããçµæãéè¨ãã¦ããã¾ãã"-v"ãªãã·ã§ã³ã§çµæã詳ãã表示ã
ãããã"--ext"ã"--exec"ãæå®ããã®ãé¢åã§ããã°ã".proverc"ã¨ããè¨å®ãã¡ã¤ã«ãç¨æãã¦ããã°ããã«è¨è¿°ããããªãã·ã§ã³ã使ç¨ãããããã«ãªãã¾ãã
$ cat ./.proverc --exec=/Users/sugyan/.nvm/v0.4.3/bin/node --ext=.js $ prove t/fuga.js .. ok t/hoge.js .. ok All tests successful. Files=2, Tests=6, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.13 cusr 0.02 csys = 0.18 CPU) Result: PASS
ããã§proveã使ã£ã¦ã¹ã ã¼ãºã«éçºãé²ãããã¨ãã§ããããã«ãªãããã§ãã
ãã¾ã
ä¸è¨ã®ä¾ã§ã¯qunitãgithubããcloneãã¦æã£ã¦ãããã©ãqunit-tapã®npmããã±ã¼ã¸ã«ãå ¥ã£ã¦ããã®ã§ããããè½ã¨ãã¦ããªãã¦ããã¹ã辿ãã°qunitã®ãã¼ããã§ãã¾ãã
exports = module.exports = global; var path = require('path'); QUnit = require(path.join(path.dirname(require.resolve('qunit-tap')), '..', 'vendor', 'qunit', 'qunit', 'qunit')).QUnit; require("qunit-tap").qunitTap(QUnit, require("sys").puts, { noPlan: true }); QUnit.init(); exports.assert = QUnit;
ãããªãããã§test_helper.jsãç¨æãã¦ããã¶ã大ä¸å¤«ã
åèURLãè¬è¾
QUnit-TAP : JavaScript のテスティングフレームワークQUnitからTAP出力する - t-wadaの日記
id:t-wadaããã«ã¯node.jsã§qunit-tapã使ãã«ãããè²ã
ã¨ç¸è«ã«ä¹ã£ã¦ããã ã ãã使ããããããã«èª¿æ´ãã¦ããã ããã æ¬å½ã«ãä¸è©±ã«ãªãã¾ããããããã¨ããããã¾ããï¼ï¼