All Projects → apache → Cordova Plugin Test Framework

apache / Cordova Plugin Test Framework

Licence: apache-2.0
Apache Cordova

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language
csharp
926 projects
cplusplus
227 projects

Projects that are alternatives of or similar to Cordova Plugin Test Framework

Cordova Cli
Apache Cordova CLI
Stars: ✭ 861 (+1204.55%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Camera
Apache Cordova Plugin camera
Stars: ✭ 879 (+1231.82%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Whitelist
Apache Cordova plugin whitelist
Stars: ✭ 442 (+569.7%)
Mutual labels:  library, mobile, cordova
Cordova Plugin File
Apache Cordova Plugin file
Stars: ✭ 664 (+906.06%)
Mutual labels:  library, mobile, cordova
Cordova Firefoxos
[DEPRECATED] Apache Cordova firefoxos
Stars: ✭ 41 (-37.88%)
Mutual labels:  library, mobile, cordova
Cordova Plugman
Apache Cordova Plugman
Stars: ✭ 379 (+474.24%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Inappbrowser
Apache Cordova Plugin inappbrowser
Stars: ✭ 994 (+1406.06%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Device
Apache Cordova Plugin device
Stars: ✭ 327 (+395.45%)
Mutual labels:  library, mobile, cordova
Cordova App Harness
[DEPRECATED] Apache Cordova app harness
Stars: ✭ 49 (-25.76%)
Mutual labels:  library, mobile, cordova
Cordova Plugin File Transfer
Apache Cordova Plugin file-transfer
Stars: ✭ 537 (+713.64%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Wkwebview Engine
[DEPRECATED] Apache Cordova wkwebview engine plugin
Stars: ✭ 607 (+819.7%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Device Motion
Apache Cordova Plugin device-motion
Stars: ✭ 58 (-12.12%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Splashscreen
Apache Cordova Plugin splashscreen
Stars: ✭ 602 (+812.12%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Network Information
Apache Cordova Plugin network-information
Stars: ✭ 429 (+550%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Media
Apache Cordova Plugin media
Stars: ✭ 338 (+412.12%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Geolocation
Apache Cordova Plugin geolocation
Stars: ✭ 584 (+784.85%)
Mutual labels:  library, mobile, cordova
Framework7
Full featured HTML framework for building iOS & Android apps
Stars: ✭ 16,560 (+24990.91%)
Mutual labels:  library, mobile, cordova
Cordova
Apache Cordova
Stars: ✭ 291 (+340.91%)
Mutual labels:  library, mobile, cordova
Cordova Weinre
Mirror of Apache Weinre
Stars: ✭ 506 (+666.67%)
Mutual labels:  library, mobile, cordova
Cordova Plugin Statusbar
Apache Cordova
Stars: ✭ 581 (+780.3%)
Mutual labels:  library, mobile, cordova

Node CI GitHub version npm version

Cordova Plugin Test Framework

The cordova-plugin-test-framework plugin allows plugin authors to add tests (manual and automated) to their plugins. To achieve this it

  1. defines the interface for Cordova plugins to write tests and
  2. provides a test harness for actually running those tests

Tests run directly inside existing Cordova projects, so you can rapidly switch between testing and development. You can also be sure that your test suite is testing the exact versions of plugins and platforms that your app is using.

TLDR; Try it

  1. Use your existing Cordova app, or create a new one.

  2. Plugins bundle their tests using a nested plugin in a /tests directory. Here are a few examples how install both:

    cordova plugin add cordova-plugin-device
    cordova plugin add plugins/cordova-plugin-device/tests
    
    cordova plugin add cordova-plugin-device-motion
    cordova plugin add plugins/cordova-plugin-device-motion/tests
    
    cordova plugin add cordova-plugin-geolocation
    cordova plugin add plugins/cordova-plugin-geolocation/tests
    

    To install the plugin from master on GitHub instead of npm, replace e.g. cordova-plugin-device with https://github.com/apache/cordova-plugin-device.git

  3. Follow the docs for Setting up the test harness.

Writing Plugin Tests

Where do tests live?

Add a directory named tests to the root of your plugin. Within this directory, create a nested plugin.xml for the tests plugin. It should have a plugin id with the form pluginid-tests (e.g. the cordova-plugin-device plugin has the nested id cordova-plugin-device-tests) and should contain a <js-module> named tests. E.g:

<js-module src="tests/tests.js" name="tests">
</js-module>

For example, the cordova-plugin-device plugin has this nested plugin.xml.

Create a package.json inside your project's tests/ folder. Plugins require a package.json now and tests are considered their own plugins. The latest version of the tools ensure to run npm install on any plugin added to a project and pull in any dependencies. Therefore, plugin authors can now put npm dependencies around their tests into the package.json file.

For example, the cordova-plugin-device plugin contains a package.json.

The cordova-plugin-test-framework plugin will automatically find all tests modules across all plugins for which the nested tests plugin is installed.

Defining Auto Tests

Export a function named defineAutoTests, which defines your auto-tests when run. Use the jasmine-2.9 format. E.g.:

exports.defineAutoTests = function() {

  describe('awesome tests', function() {
    it('do something sync', function() {
      expect(1).toBe(1);
      ...
    });

    it('do something async using callbacks', function(done) {
      setTimeout(function() {
        expect(1).toBe(1);
        ...
        done();
      }, 100);
    });

    it("do something async using promises", function() {
      return soon().then(function() {
        value++;
        expect(value).toBeGreaterThan(0);
      });
    });

    it("do something async using async/await", async function() {
      await soon();
      value++;
      expect(value).toBeGreaterThan(0);
    });
  });

  describe('more awesome tests', function() {
    ...
  });

};

Note: Your tests will automatically be labeled with your plugin id, so do not prefix your test descriptions.

Defining Manual Tests

Export a function named defineManualTests, which defines your manual-tests when run. Manual tests do not any test runner, and success/failure results are not officially reported in any standard way. Instead, create buttons to run arbitrary javascript when clicked, and display output to user using console or by manipulating a provided DOM element. E.g.:

exports.defineManualTests = function(contentEl, createActionButton) {

  createActionButton('Simple Test', function() {
    console.log(JSON.stringify(foo, null, '\t'));
  });

  createActionButton('Complex Test', function() {
    contentEl.innerHTML = ...;
  });

};

Make sure to document the expected outcome.

Note: Your tests will automatically be labeled with your plugin id, so do not prefix your test descriptions.

Example

See: cordova-plugin-device tests.

Running Plugin Tests

  1. Use your existing Cordova app, or create a new one.

  2. Add this plugin:

    cordova plugin add cordova-plugin-test-framework
    // or
    cordova plugin add https://github.com/apache/cordova-plugin-test-framework.git
    
  3. Change the start page in config.xml with <content src="cdvtests/index.html" /> or add a link to cdvtests/index.html from within your app.

  4. Thats it!

FAQ

  • Q: Should I add cordova-plugin-test-framework as a <dependency> of my plugin?

    • A: No. The end-user should decide if they want to install the test framework, not your plugin (most users won't).
  • Q: What do I do if my plugin tests must have very large assets?

    • A: Don't bundle those assets with your plugin. If you can, have your tests fail gracefully if those assets don't don't exist (perhaps log a warning, perhaps fail a single asset-checking test, and skip the rest). Then, ideally download those assets automatically into local storage the first time tests run. Or create a manual test step to download and install assets. As a final alternative, split those test assets into a separate plugin, and instruct users to install that plugin to run your full test suite.
  • Q: Should I ship my app with the test framework plugin installed?

    • A: Not likely. If you want, you can. Then your app could even embed a link to the test page (cdvtests/index.html) from a help section of your app, to give end users a way to run your test suite out in the feild. That may help diagnose causes of issues within your app. Maybe.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].