CI Tools and Best Practices in the Cloud

Continuous Integration

Subscribe to Continuous Integration: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Continuous Integration: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Continuous Integration Authors: Pat Romanski, Liz McMillan, Elizabeth White, Stackify Blog, Yeshim Deniz

Related Topics: Continuous Integration

Blog Feed Post

Automating SproutCore Unit Testing with PhantomJS

One of the new features in SproutCore v1.10.0 was a PhantomJS unit test runner. It allowed us to automate SproutCore’s own framework unit tests, giving us awesome continuous integration support right in GitHub via the great Travis-CI service.

If you use CoreTest, SproutCore’s built-in (QUnit-like) unit test framework, then you can also use this to run your own tests from the command line – meaning you can automate it, and hook it up to your own CI scaffolding. It’s impossible to overstate the impact that continuous, automatic unit testing has on the quality and stability of your codebase.


You will need to have PhantomJS installed before using the test runner. Full instructions for this can be found here.

You will also need to track down SproutCore’s installed location in order to run its test runner script. If you’ve got a copy checked out into your project’s frameworks directory, great! Just use that. If you’re using the gem, you’ll have to track it down yourself. It’s usually somewhere like ~/.rvm/gems/ruby-1.9.3-p374/gems/sproutcore-1.10.2 – if you’re unable to track it down, run gem env and look under the GEM PATHS heading for a hint. In the below examples, SproutCore’s install path is represented by $SC_PATH; you’ll have to point the commands to your actual install location.

Running the tests

First, start sc-server as you normally would. Once that is running, we can start the test runner. (See note above about $SC_PATH above.)

phantomjs $SC_PATH/lib/frameworks/sproutcore/phantomjs/test_runner.js

By default, this will run all the unit tests that abbot knows about, including the tests in SproutCore itself. This is probably not what you want, so you can use the --include-targets flag to tell the test runner what tests you want to run.

For example, if your app is called todos, running

phantomjs $SC_PATH/lib/frameworks/sproutcore/phantomjs/test_runner.js --include-targets=/todos

will run only the unit tests in your app. If you also have a framework you want to test, you can make the argument to –include-targets a comma-delimited list of targets:

phantomjs $SC_PATH/lib/frameworks/sproutcore/phantomjs/test_runner.js --include-targets=/todos,/my_framework

There are a few other options available for excluding certains tests and only running certain types of tests (app, framework, etc). For the full list, run:

phantomjs $SC_PATH/lib/frameworks/sproutcore/phantomjs/test_runner.js --help

Read the original blog entry...

More Stories By Charles Jolley

Charles Jolley is the creator of SproutCore and CEO of Sproutit, which provides consulting and software services for building SproutCore applications on the web. He has helped build some of the most popular RIAs on the web today.