Differences between revisions 24 and 25
Revision 24 as of 2015-03-27 17:20:57
Size: 7010
Editor: MuratSutunc
Revision 25 as of 2015-04-07 18:54:04
Size: 493
Editor: AndrewGrieve
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Testing the Device API == Most tests run as a part of the [[https://github.com/apache/cordova-mobile-spec/blob/master/README.md|mobile-spec project]].
Line 3: Line 3:
The device api tests live in a project called [[http://git-wip-us.apache.org/repos/asf?p=cordova-mobile-spec.git;a=summary|mobile-spec]].
 * They run in an Apache Cordova shell:
  1. Create an Apache Cordova project
  1. include the test suite in the www folder.
 * The tests will run when the application is launched.
Android has some [[https://github.com/apache/cordova-android/blob/master/test/README.md|instrumentation tests]]
Line 9: Line 5:
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,
  1. hit the "Automatic Tests" button,
  1. select which specific API to test (or select "all" to run them all).
 1. 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'''
 1. 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.
 1. Make changes to either the cordova-js code or the native code.
 1. Rebuild Cordova and/or the !JavaScript and re-run the mobile-spec tests.
 1. Compare the number of failing tests.
 1. 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.
 1. Navigate to the /test directory
 1. 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`
 1. Select the `/test` directory
 1. Right click the project, and select `Debug As` -> `Android Project`
 1. Right click the project, and select `Debug As` -> `Android JUnit Project`.

=== On iOS ===
Running from within `Xcode`:
iOS has some unit tests:
Line 66: Line 11:
== 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
 1. 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
 1. Test '''Battery'''.
  1. Load the page up,
  1. click "Add batterystatus listener"
  1. 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".
 1. 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.
 1. Test '''Compass'''. Make sure you can:
   * get the current heading
   * watch the heading
   * can stop the watch
 1. 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.
 1. Test '''Events'''.
  * Steps:
   1. Load the page
   1. in turn, click each event to intercept,
   1. run the device through the motions to fire that event,
   1. go back to the app and make sure the event is listed in the box,
   1. stop intercepting that event,
   1. run the device through the motions of that event again,
   1. 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
 1. Test '''Location'''. Make sure you can:
   * get the current location
   * watch the location
   * stop the watch
 1. 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.
 1. Test '''Notifications'''. Make sure you can:
   * beep
   * vibrate
   * show a native alert
   * show a native confirm dialog

=== Platform-specific manual tests ===

* [[iOSManualTests | iOS Manual Tests]]

== Testing Cordova and Plugman Node CLI ==

* [[CordovaCLIManualTests | Cordova CLI Manual Tests]]

=== Linting rules for Cordova ===
It is expected to run `npm test` before each commit, which in return will run jsHint. The default rules for jsHint are "node": true, "bitwise": true, "undef": true, "trailing": true, "quotmark": true, "indent": 4, "unused": "vars" and "latedef": "nofunc". By default node_modules folder is ignored. For platforms, we also ignore contents of project template folder. If you feel that a particular error doesn't apply to a file, please extend the rules in comment form for that file.

=== 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
 1. 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
 1. 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
 1. Don't run global `jasmine-node`, it might be a different version than the one in `cordova-cli/plugman` / `package.json`
Many repos also have unit tests via `npm test`

Most tests run as a part of the mobile-spec project.

Android has some instrumentation tests

iOS has some unit tests:

  1. Open CordovaLibTests/CordovaTests.xcodeproj

  2. Click Product->New Scheme

  3. Select the CordovaLibTests Target and click OK

  4. Click Product->Test

Many repos also have unit tests via npm test

RunningTests (last edited 2015-04-07 18:54:04 by AndrewGrieve)