Testing Cordova Applications
You can also skip the IDEs entirely and test the applications directly from the command line; I show you how in the following sections.
Run a Cordova Application on a Device Simulator
Most mobile device manufacturers provide a software program that emulates or simulates a mobile device. This allows developers to easily test their mobile applications when they don’t have a physical device. Performance isn’t usually the same, but it looks and acts like a real device much as it can. In some cases, what’s provided is generic and simply mimics the capabilities of the specific OS version, while for other mobile platforms it might mimic specific devices. Either way, there’s a software-only solution available that developers can use to test Cordova applications in an almost real-world scenario (I’ll explain “almost real-world” in the following section). Google, for example, provides Android emulators, and Apple and BlackBerry provide simulators of their devices.
To run a Cordova application using a device simulator, you would use the following command:
cordova emulate device_platform
Replace the value for device_platform with the name of the mobile device platform you wish to emulate (android, blackberry10, ios, wp8, and so on). For example, to run the application on a BlackBerry 10 simulator, you would issue the following command:
cordova emulate blackberry10
In this example, the CLI will prepare the files, build the application using the platform’s command-line tools, then launch the appropriate simulator and run the application. You saw examples of the device simulators and emulators in the screenshots found in Chapter 5, “Anatomy of a Cordova Application.”
Run a Cordova Application on a Physical Device
Before you deploy your application to mobile users, you should perform final testing on a physical device. As good as these options are, there is always something that doesn’t work quite right on a simulator. To test an application on a physical device, connect the device to your development system using a USB cable, then issue the following command:
cordova run device_platform
For example, to run the application on an Android device, issue the following command:
cordova run android
Behind the scenes, the CLI will execute the prepare command described earlier, then call the particular platform’s command-line tools to package the application and deploy it to the device that is connected to the system. Within seconds (or as much as a few minutes in the case of some platforms), the application will appear on the device’s screen.