How can you test Ionic applications?
Testing your Ionic app
There are four ways to test your app as you develop:
- Desktop browser testing
- Simulator testing
- Mobile browser testing
- Testing as a native app
Desktop browser testing:
Testing your app in a web browser is simple.Just type below command in your project’s root folder from the terminal.
$ ionic serve
You can also test right in the simulator using the cordova commands. For example, to test in the android simulator, run:
$ ionic cordova build android
$ ionic cordova emulate android
If you want to get advanced, you can also open up the project file for a specific platform by opening the required Xcode or Android Eclipse project in platforms/PLATFORM inside the root of your project. Then, you can build and test from inside the platform-specific IDE. Note: if you go this route, I recommend still working inside of the root www folder, and when you’ve made changes to this folder, run the command:
$ ionic cordova prepare android
Which will update the android specific project with the code from the www folder. Note: this will overwrite any changes you’ve made to the platforms/android/www and other platform-specific folders.
Mobile browser testing:
You can also test the app directly in a mobile browser .Kindly use Chrome for remote debugging. If you are using the local server method from the Desktop testing section and you are on the same network as the desktop computer, you can connect to the ip address of the desktop computer to test. So, if our desktop is running a test server at 188.8.131.52:8000, we can just load that address into our mobile Chrome to test the project Or App.
One problem with testing in a mobile browser is that it’s probably the furthest of the three options from the actual app experience. This is largely because the browser app is meant for browsing websites, so it often adds functionality that conflicts with your app. For example, Chrome and Safari both listen for drag events on the sides of the app which let you s*** between open tabs. They also have issues with the URL bars getting in the way, and some scrolling behavior is not the same as it is in the web view running in Cordova. It is fine for small tests, but not recommended for more complex apps.
Testing as a native app:
Testing on Android is much easier and faster. To test on the device, simply plug it in, and run
$ ionic cordova run android
If this doesn’t work, make sure you have USB debugging enabled on your device.