cordova-plugin-device
, one of the plug-ins supported by the Apache Cordova community): it("should exist", function() { expect(window.device).toBeDefined(); }); it("should contain a platform specification that is a string", function() { expect(window.device.platform).toBeDefined(); expect((new String(window.device.platform)).length > 0).toBe(true); }); it("should contain a version specification that is a string", function() { expect(window.device.version).toBeDefined(); expect((new String(window.device.version)).length > 0).toBe(true); });
cordova-plugin-test-framework
- another plug-in that adds an interface to the application to run tests as a separate page with controls to start, stop and select tests to run, and also loads all announced tests while the application is running and running them.test-framework
provides the ability to quickly create so-called. manual tests - create several buttons on a separate page with a description of the actions associated with clicking on each button and the expected behavior of the application.test-framework
pick them up, but it contains some inaccuracies, so I’ll briefly summarize the main points here./tests
main plugin.tests
, (for example <js-module src="tests/tests.js" name="my.plugin.tests">
) exports.defineAutoTests = function() { }; exports.defineManualTests = function(contentEl, createActionButton) {};
cordova-plugin-test-framework
- and perhaps also the plugin to be tested - as a dependency for your tests, so that they are installed automatically along with the tests. This is done by adding the following elements to tests/plugin.xml
: <dependency id="cordova-plugin-test-framework"/> <dependency id="my-awesome-plugin" url=".." />
plugin.xml
will look like this: <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="my-awesome-tests" version="0.0.1"> <name>My Awesome Plugin Tests</name> <dependency id="cordova-plugin-test-framework" /> <dependency id="my-awesome-plugin" url=".." /> <js-module src="tests.js" name="tests" /> </plugin>
tests.js
: exports.defineAutoTests = function() { // To be done }; exports.defineManualTests = function(content, createActionButton) { // To be done };
$EDITOR
, or you can use plugman
, another tool for working with Apache Cordova plugins: npm install -g plugman plugman create --name "My awesome plugin tests" --plugin_id my-awesome-plugin-tests --plugin_version 0.0.1 --path=./tests
exports.defineAutoTests = function() { describe('plugin', function() { it('should be exposed as cordova.plugins.MyAwesomePlugin object', function() { expect(cordova.plugins.MyAwesomePlugin).toBeDefined(); expect(cordova.require('my-awesome-plugin.MyAwesomePlugin')) .toBe(cordova.plugins.MyAwesomePlugin); }); it('should have corresponding methods defined', function() { ['coolMethod', 'logCoolMessage'].forEach(function(methodName) { expect(cordova.plugins.MyAwesomePlugin[methodName]).toBeDefined(); expect(cordova.plugins.MyAwesomePlugin[methodName]).toEqual(jasmine.any(Function)); }); }); }); };
cordova create my-sample-app && cd my-sample-app cordova platform add android --save cordova plugin add .. ../tests --save
<content src="index.html" />
element in the config.xml
file inside our test application — change the value to cdvtests/index.html
. It is necessary that instead of the main start page when you start the application, the plugin page opens and loads the test-framework
. cordova run
test-framework
works, you can easily write any number of automated tests for your plugin.test-framework
assumes that each test has its own button in the interface and a field common to all tests in which you can display your results. These are the createActionButton
and content
parameters respectively for the defineManualTests
function.createActionButton
is a function that creates a button, adds it to the DOM inside the specified element, and performs the specified function when the button is clicked. Function parameters look like this: `function createActionButton(' ', _, '_') {...}`
content
is a container on the page, inside which you can put information about the test and describe the verification process for the tester. exports.defineManualTests = function(contentEl, createActionButton) { var show_preferences_test = '<h3>Press "Open preferences" button to show preferences pane</h3>' + '<div id="open_prefs"></div>' + 'Expected result: A "Preferences" box should appear'; contentEl.innerHTML = '<div id="info"></div>' + show_preferences_test; var log = document.getElementById('info'); var logMessage = function (message) { var logLine = document.createElement('div'); logLine.innerHTML = message; log.appendChild(logLine); }; createActionButton('Open preferences', function() { log.innerHTML = ''; // cleanup log area plugins.appPreferences.show(function(result) { logMessage(result); }, function(error) { logMessage(error); }); }, "open_prefs"); };
cordova plugin rm my-awesome-plugin-tests && cordova run
run
command before building the application will restore the deleted plugin from its original location along with the updated files, and all changes will be included in the application.cordova-paramedic
. This application is written specifically to automate the launch of tests for plug-ins including. and for CI. Here is what it does:paramedic
, install it and add our plugin to the package.json
: npm install cordova-paramedic --save-dev
"scripts": { ... "test-android": "cordova-paramedic --platform android --plugin ./ --verbose", "test-ios": "cordova-paramedic --platform ios --plugin ./ --verbose" },
config.xml
, run it and then watch how the points and crosses of the passed and fallen tests appear, simply run the corresponding script, for example for Android: npm run test-android
... Results: ran 2 specs with 0 failures result code is : 0 {"mobilespec":{"specs":2,"failures":0,"results":[]},"platform":"Desktop","version":"5.1.0","timestamp":1455530481,"model":"none"}
.travis.yml
language: objective-c install: - npm install script: - npm run test-ios
circle.yml
test: pre: - emulator -avd circleci-android21 -no-audio -no-window: background: true parallel: true - circle-android wait-for-boot override: - npm run test-android
Source: https://habr.com/ru/post/277615/
All Articles