Ionic have created an official unit testing example over at driftyco/ionic-unit-testing-example. To understand why this repo still exists, see #239, where we looked at deprecating clicker
in favour of ionic-unit-testing-example
.
Broadly, the official example repo:
- Is not mature or production ready
- Is intended as a simple example only / will not be supported by Ionic
- Does not support e2e
- Does not use
@angular/cli
and thus lacks testing support from the wider ng2 community
For ~large or production projects, I suggest using clicker. For small apps / side projects the official example should suffice.
You need to be running the latest node LTS or newer
git clone https://github.com/lathonez/clicker.git
cd clicker
npm install
npm start # start the application (ionic serve)
Running as root? You probably shouldn't be. If you need to: npm run postinstall
before npm start
. #111 for more info.
npm test # run unit tests
npm run e2e
Some extra setup is needed to test your Ionic app on an emulator. The following is based on the configuration file at this version of clicker.
Install and/or update the Android SDK. Create a virtual device for emulation. protractor-android.config assumes a Nexus 5X, running Android 7.1.1.
Add the Android platform to your app and deploy
ionic platform add android
ionic emulate android
The app should deploy and you should be able to interact with it.
If so, edit the capabilities object in protractor-android.conf.js to
have the correct device name, platform version, AVD name, and full path
to your Android android-debug.apk
file. Note: shell shortcuts such as ~/
will not
work here.
capabilities: {
browserName: '',
'appium-version': '1.6.4',
platformName: 'android',
platformVersion: '7.1.1',
deviceName: 'emulator-5554',
autoWebview: true,
avd: 'Nexus_5X_API_25',
nativeInstrumentsLib: true,
app: "/full/path/to/your/apk/android-debug.apk"
},
Install [Appium[(http://appium.io/). Appium is a server that will relay information between Protractor and the emulator.
npm install appium@latest -g
Start Appium.
appium
Start the emulator again, if you stopped it.
ionic emulate android
After Appium and the emulator are both ready, run the E2E Android emulator test script.
npm run e2e-android
If everything works, you should see some of the Protractor tests executing on the emulator. Others fail right now with errors related to what is and is not clickable.
If you get an error in Appium about ChromeDriver being out of date, download the latest version. The "appium" script in package.json assumes you put ChromeDriver in /usr/local/bin, so that you can start Appium with
npm run appium
If you get any other Appium errors, try installing and running appium-doctor.
PRs are welcome, see the roadmap sticky
- If you can't get the testing working, raise an issue
- If you have a general question about unit testing (e.g. how can I write a unit test for
some-module
), see #191
- This started out as a fork of Angular 2 Seed and would not be possible without it
- @bengro for the lightweightify inspiration (#68)
- @ric9176 and @DanielaGSB for E2E tests (#50)
- @tja4472 for the ngrx implementation (#133)
- Everyone else for the advice, help, PRs etc
See the changelog here
- @angular/*: 4.0.0
- @angular/cli:: 1.0.0
- @ionic-angular: 3.0.1