Differences between revisions 21 and 22
Revision 21 as of 2013-11-07 12:58:13
Size: 6429
Editor: JoshSoref
Comment: Wikify page
Revision 22 as of 2013-11-12 00:45:41
Size: 6487
Deletions are marked like this. Additions are marked like this.
Line 136: Line 136:
* [[CordovaCLIManualTests | Cordova CLI Manual Tests]]

Testing the Device API

The device api tests live in a project called mobile-spec.

  • They run in an Apache Cordova shell:
    1. Create an Apache Cordova project
    2. include the test suite in the www folder.
  • The tests will run when the application is launched.

There are two parts to the Mobile Spec:

  1. a suite of Jasmine tests that assert things about the Cordova JavaScript API.

    1. Load mobile-spec up on your device,
    2. hit the "Automatic Tests" button,
    3. select which specific API to test (or select "all" to run them all).
  2. a series of "manual" tests.
    • Linked from the project's root page.
    • Run through each one to make sure baseline functionality works as expected.
    • The section below spells out the details of what should be done and the expected behaviour.

Whitelist Exceptions Needed

  1. File Transfer Tests - ajax.googleapis.com

  2. Media Tests - audio.ibeat.org

Testing Procedure

  1. As a baseline, run the Jasmine Mobile Spec tests and note the number of tests passing/failing.
    • Use this a baseline when comparing changes you make. Not all platforms pass all of the tests 100%.
    • More than 50 failing tests is generally not acceptable.

  2. Make changes to either the cordova-js code or the native code.
  3. Rebuild Cordova and/or the JavaScript and re-run the mobile-spec tests.

  4. Compare the number of failing tests.
  5. Rinse and repeat until the number of failing tests is not more than before your change.

Running Unit Test

On Android

Pre-steps for both command line and Eclipse:

  1. Ensure an emulator or device is running.
  2. Navigate to the /test directory
  3. Run:

android update project -p . -t android-16 --subprojects

Running from command line:

ant debug install
adb shell am instrument -w org.apache.cordova.test/android.test.InstrumentationTestRunner

Running from within Eclipse:

  1. File -> New -> Android Project from Existing Code

  2. Select the /test directory

  3. Right click the project, and select Debug As -> Android Project

  4. Right click the project, and select Debug As -> Android JUnit Project.

On iOS

Running from within Xcode:

  1. Open CordovaLibTests/CordovaTests.xcodeproj

  2. Click Product->New Scheme

  3. Select the CordovaLibTests Target and click OK

  4. Click Product->Test

Testing the Native Plugin API


Tests that need to be run manually

When you load up mobile-spec, you will see a series of buttons. Each one of these (except for the "Automatic Tests" button) will load a separate page encapsulating manual tests for the various APIs. The below list lays out the expectations for each manual test page.

  1. Test Accelerometer. Make sure you can:

    • get the current acceleration
    • watch the acceleration
    • stop the watch
  2. Test Audio.

    • Make sure your application has http://audio.ibeat.org added to the whitelist!

    • Make sure you can:
      • play
      • pause
      • stop audio playing (should be a little guitar riff).
    • Make sure you can:
      • record audio
      • play/pause/stop that functionality as well
  3. Test Battery.

    1. Load the page up,
    2. click "Add batterystatus listener"
    3. plug it into a connected USB cable or wall charger.
      • You should see the actual level of the battery show up in the box (if supported on your platform) as well as the plugged in label reading "true".
  4. Test Camera. You should be able to:

    • take a picture and have it show up on the test page,
    • select a picture from the library (if supported on your platform) and have that picture show up on the test page as well.
  5. Test Compass. Make sure you can:

    • get the current heading
    • watch the heading
    • can stop the watch
  6. Test Contacts. You should be able to:

    • pull the entire contact list from your phone into the box on the page (this can take a while depending on how many contacts you have on your device).
    • create a new contact.
      • Verify this with the built-in Contact viewing app your device comes with.
  7. Test Events.

    • Steps:
      1. Load the page
      2. in turn, click each event to intercept,
      3. run the device through the motions to fire that event,
      4. go back to the app and make sure the event is listed in the box,
      5. stop intercepting that event,
      6. run the device through the motions of that event again,
      7. finally go back to the app and make sure that the event does not get printed into the output box twice (to test for unregistration).
    • Events:
      • offline/online - remove/add SIM card and/or turn off/on WiFi and/or go into/out of Airplane mode

      • pause/resume - press the Home button when a multi-tasking app is running, launch it back again
      • resign/active - lock/unlock the iOS device
      • different buttons - only if supported on your platform
  8. Test Location. Make sure you can:

    • get the current location
    • watch the location
    • stop the watch
  9. Test Network. When you load this page up, make sure that:

    • the network state box prints out the proper type of network connection your device is running under currently.
  10. Test Notifications. Make sure you can:

    • beep
    • vibrate
    • show a native alert
    • show a native confirm dialog

Platform-specific manual tests

* iOS Manual Tests

Testing Cordova and Plugman Node CLI

* Cordova CLI Manual Tests

Tips using jasmine-node

  1. Use npm test this calls > package.json "scripts": { "test": "jasmine-node --color spec"}

    • Remember when using npm that jasmine-node binary is added to the $PATH temporarily

  2. If something breaks (red F), then run verbose: ./node_modules/jasmine-node/bin/jasmine-node  spec --verbose

    • Very useful to pin point spec.js that has the failing test, then do step 3
  3. To run a single spec.js use ./node_modules/jasmine-node/bin/jasmine-node spec/run.spec.js --verbose

    • Much faster iteration, code & test. But remember to run full suite before pushing code

  4. Don't run global jasmine-node, it might be a different version than the one in cordova-cli/plugman / package.json