前回の記事「gulpでmochaのテストをできるようにする」でコマンドラインからのテストを可能にしました。
今回は、テスト結果をJUnit形式のXMLファイルに出力させるようにして、それをJenkinsで集計できるようにします。
テスト結果をJUnit形式のXMLファイルに出力させる
gulp-mochaでテスト結果をXMLファイルに出力させるには、次のような手順でxunit-fileを利用します。
gulp-mocha内のmochaにxunit-fileを追加します
12$
cd
node_modules
/gulp-mocha/node_modules/mocha/
$ npm
install
--save-dev xunit-
file
gulpfileの
test
タスク内のreporter
をxunit-file
に変更します1234# test
gulp.task
'test'
,
[
'script'
]
,
-
>
gulp.src
[
'lib/*.js'
,
'test/*.coffee'
]
.pipe mocha
{
reporter:
'xunit-file'
}
これで、gulp test
を実行するとxunit.xmlが生成されるようになります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $ gulp test [gulp] Using file /Users/safx/src/mantle-gen/gulpfile .js [gulp] Working directory changed to /Users/safx/src/mantle-gen [gulp] Running 'script' ... [gulp] Finished 'script' in 24 ms [gulp] Running 'test' ... foo() ◦ は引数ありなら正負を逆にした値を返す ◦ は0なら0を返す ◦ は引数なしなら0を返す [gulp] Finished 'test' in 49 ms $ cat xunit.xml <testsuite name= "Mocha Tests" tests= "3" failures= "0" errors= "0" skipped= "0" timestamp= "Sat, 01 Feb 2014 15:54:15 GMT" time = "0.003" > <testcase classname= "foo()" name= "は引数ありなら正負を逆にした値を返す" time = "0" /> <testcase classname= "foo()" name= "は0なら0を返す" time = "0" /> <testcase classname= "foo()" name= "は引数なしなら0を返す" time = "0" /> < /testsuite > |
Jenkinsでテスト結果を集計する
Jenkinsでテストさせるには、シェルの実行でgulp test
させて、テスト結果のxunit.xmlを集計させるようにするだけです。
これで、実行するとリポートが集計されていきます。
ただし、npmパッケージが更新されることを考慮するなら、「シェルの実行」は次のようにしておくほうがよいでしょう。
1 2 3 4 5 6 7 | npm install [ -f node_modules /gulp-mocha/node_modules/mocha ] && \ cd node_modules /gulp-mocha/node_modules/mocha && \ npm install --save-dev xunit- file gulp test |
おわりに
gulpによるテスト結果をJenkinsで集計できるようにしました。
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。