Skip to content

Unit testing and E2E Testing

leob edited this page Feb 26, 2016 · 10 revisions

End to End (E2E) Testing

Note: This is currently a work in progress at github.com/tjaffri/ionic-quickstarter.

The project is set up for basic end to end (E2E) testing via protractor. You can read more about protractor here.

Machine Setup

Make sure your machine has python installed. Type python in the command line you use for building, and if it is not found, please install python from python.org.

Note that you may also need to add python to your path, especially if you are installing on Windows and running from PowerShell.

You will also need the Java Runtime Environment. Web driver will prompt you to install it, if you don't have it already installed.

If you're on a Mac, make sure you install the JRE from Apple, not Oracle. See here: https://support.apple.com/kb/DL1572

The tests use Google Chrome by default. You can change what browser you use in the protractor.conf.js file, or just make sure you have the Chrome browser installed on the machine you are using to test.

Finally, you don't need to install protractor globally. The provided protractor configuration will install a local copy of protractor, along with any necessary web driver plugins.

Running tests

To run the e2e tests, you need a running instance of your app. By default, the e2e tests currently run against a locally hosted instance of your app i.e. at http://localhost:8100. This can be changed in the protractor.conf.js file.

A typical workflow to run the e2e tests would be to first run the app by calling:

ionic serve

Next, you might want to create a new shell instance (since ionic serve will take over the first shell that you used to serve your app). From the second shell, call:

npm run protractor

Protractor will run all the tests as referenced in protractor.conf.js and will print the results to the console. You will see the browser launch (chrome by default), and all your test scenarios played out just like a user would by interacting with the browser.

Test Structure

The e2e tests are in the test/e2e folder. The recommended approach to write e2e tests is to organize them by user scenario, rather than modules in your code. The e2e tests should emulate user behavior for your most critical scenarios.

References

  1. http://learn.ionicframework.com/formulas/Protractor/
  2. http://angular.github.io/protractor/#/tutorial