Testing the Device API
Currently the device api tests live in a project called mobile-spec which, being a set of webpages, needs to be run in an Apache Cordova shell. Simply create an Apache Cordova project and 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:
a suite of Jasmine tests that assert things about the Cordova JavaScript API. When you load mobile-spec up on your device, hit the "Automatic Tests" button, and select which specific API to test (or select "all" to run them all).
- a series of "manual" tests. These are all linked from the project's root page. You should 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
File Transfer Tests - ajax.googleapis.com
Media Tests - audio.ibeat.org
Testing Procedure
- 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%, but less than 50 failing tests is an acceptable number.
- Make changes to either the cordova-js code or the native code.
Rebuild Cordova and/or the JavaScript and re-run the mobile-spec tests.
- Compare the number of failing tests.
- Rinse and repeat until you get the same (or possibly even less!) number of tests failing.
Running Unit Test
On Android
Pre-steps for both command line and Eclipse:
- Ensure an emulator or device is running.
- Navigate to the /test directory
- 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:
File -> New -> Android Project from Existing Code
- Select the /test directory
Right click the project, and select Debug As -> Android Project
Right click the project, and select Debug As -> Android JUnit Project.
On iOS
Running from within Xcode:
Open CordovaLibTests/CordovaTests.xcodeproj
Click Product->New Scheme
Select the CordovaLibTests Target and click OK
Click Product->Test
Testing the Native Plugin API
TODO
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.
- Test the Accelerometer. Make sure you can get the current acceleration, watch the acceleration, and can stop the watch.
Test the Audio. Make sure your application has http://audio.ibeat.org added to the whitelist! Make sure you can play, pause and stop audio playing (should be a little guitar riff). Make sure you can record audio, and play/pause/stop that functionality as well.
- Test the Battery. Load the page up, click "Add batterystatus listener" and 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".
- Test the Camera. You should be able to take a picture and have it show up on the test page, as well as selecting a picture from the library (if supported on your platform) and have that picture show up on the test page as well.
- Test the Compass. Make sure you can get the current heading, watch the heading, and can stop the watch.
- Test the 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). You should also be able to create a new contact. Verify this with the built-in Contact viewing app your device comes with.
- Test the Events. Load the page and, in turn, click each event to intercept, run the device through the motions to fire that event, go back to the app and make sure the event is listed in the box, stop intercepting that event, run the device through the motions of that event again, and 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).
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
- Test the Location. Make sure you can get the current location, watch the location, and can stop the watch.
- Test the 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.
- Test the Notifications. Make sure you can beep, vibrate, show a native alert and show a native confirm dialog.