Sencha Touch BDD
A multi-part series of articles on how to test Sencha Touch applications. It uses Jasmine for unit testing and Siesta for integration testing.
Part 4 – Headless testing using PhantomJS
I hear it’s all about the cloud these days
Not only do we use Test Driven Development, we test all the time (see also TATFT). In fact, continuous testing is a key component in a well-run agile practice. Pivotal developed ciborg (previously known as Lobot), to automatically deploy Jenkins servers in the cloud. Jasmine has a continuous integration target in its rake tasks,
rake jasmine:ci. If you’ve never run it before, now is a good time to try it. You’ll notice that Jasmine launches an instance of the Firefox browser, runs the test suite, then reports the results. That’s great if you’ve got (1) Firefox and (2) a machine that has a display! When you run your CI tests in the cloud, the virtual machines may not be configured with a virtual display. Furthermore, the process is terribly slow.
In this installment, we’ll see how to mix in PhantomJS so we can run our Jasmine tests without the need for a visual browser. PhantomJS is orders of magnitude faster, too.
Do the install dance
- Add ‘jasmine-phantom’ to your
index e6b5daf..612fb25 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,4 @@ source "https://rubygems.org" gem "rake" gem "jasmine" +gem "jasmine-phantom"
and modify your
Rakefile to load the PhantomJS tasks:
--- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ begin require 'jasmine' load 'jasmine/tasks/jasmine.rake' + load 'jasmine-phantom/tasks.rake' rescue LoadError task :jasmine do
Now, when you run
rake -T from the command line, you’ll see a new target:
$ rake -T jasmine rake jasmine # Run specs via server rake jasmine:ci # Run continuous integration tests rake jasmine:phantom:ci # Run jasmine specs using phantomjs and report the results
Running it will the phantom:ci target will start the Jasmine continuous integration tests in PhantomJS instead of Firefox.
$ rake jasmine:phantom:ci 2>1 /dev/null [2013-05-06 20:28:15] INFO WEBrick 1.3.1 [2013-05-06 20:28:15] INFO ruby 1.9.3 (2012-11-10) [x86_64-darwin12.2.0] [2013-05-06 20:28:15] INFO WEBrick::HTTPServer#start: pid=17061 port=60080 Waiting for jasmine server on 60080... 8 specs | 0 failing