Cordova Plugin Test Framework
何?
- Cordova Pluginのテストフレームワーク
- PluginのJSAPIを叩いて動作を確認することができる
- できるJasmine2を利用
試してみる
device pluginのテストを動かしてみる。
まずはプロジェクトにcordova-plugin-test-frameworkを入れます。
$ cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework.git
次にdeviceプラグインとそのテストを入れます。
テストはpluginのtestsディレクトリに入っています。
$ cordova plugin add add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
$ cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git#:/tests
でconfig.xmlのタグを
<content src="cdvtests/index.html" />
に書き換えて、アプリを動かす。
Jasminでユニットテストが動作できているのが確認できます。
Manual Testsの方は
となり、手動で操作するテストの画面が出てきます。
テストの書き方
https://github.com/apache/cordova-plugin-device/blob/master/tests/tests.js
https://github.com/apache/cordova-plugin-camera/blob/master/tests/tests.js
を参照してマネして書いて欲しいのですが、
自動テストのほうは、
tests.js
exports.defineAutoTests = function() {
describe('test1', function() {
it("should exist", function() {
expect(window.foo).toBeDefined();
})
}
};
のようにdefineAutoTests内でJasmineの形式にのっとってテストを書いていけばよいです。
手動テストは
tests.js
exports.defineManualTests = function(contentEl, createActionButton) {
contentEl.innerHTML = '<div id="test"></div>';
createActionButton('test', function() {
//test contents
}, "test");
};
のようにManualTestsにテストを書き加えていきます。
contentElのinnerHTMLでコンテンツを挿入し、
createActionButton にボタンのおしたときの振る舞いを記述できます。
createActionButtonの第3引数に指定したidの場所にボタンが表示されます。