OVERVIEW
JavaScript testing is hard. Most of the time, it is just plain difficult to set up the test harness just to run Javascript tests.
CURRENT STATE
Most of my team’s existing production web applications do not use any MV* frameworks. A few newer projects use Backbone/Marionette.
We rely on the following stack:-
- Maven for creating JEE projects.
- Jenkins as continuous integration server.
- Jasmine for writing JavaScript tests.
- Jasmine Maven Plugin for running Jasmine tests.
- PhantomJS Maven Plugin for running JavaScript tests on headless browser.
- Saga Maven Plugin for code coverage.
We choose this direction because these Maven plugins provide good integration with Jenkins.
What is Wrong with the Current State
- Jasmine Maven Plugin only works with Jasmine 1.x. At the time of this post, there is one alpha release in June 2014 that moves towards Jasmine 2.x.
- Since we are relying on Jasmine 1.x, we can’t use asynchronous support from Jasmine 2.x to easily test our asynchronous calls.
- We also cannot use the latest version of Jasmine-JQuery.
- The primary developer for Saga Maven Plugin is looking for a new maintainer.
FUTURE STATE
We will now rely on the following stack:-
- Maven for creating JEE projects.
- Jenkins as continuous integration server.
- Jasmine for writing JavaScript tests.
- Istanbul for code coverage.
- Karma as JavaScript test runner.
- Karma Maven Plugin for running Karma test runner.
- Node.js for running PhantomJS.
Why This is a Better State
- Developed by Google developers, primary test harness for AngularJS.
- Allows us to use Jasmine 2.x.
- Test framework agnostic. Although we are using Jasmine now, we can easily switch to Mocha in the future.
- MV* framework agnostic. It works with any MV* or homegrown framework.
- Great integration with Jenkins.
- Great integration with IntelliJ.
- Ability to run tests on different browsers at the same time, such as Chrome, Firefox, PhantomJS, etc.
Leave a Reply