Skip to content

Testing overview

Tim Branyen edited this page Sep 29, 2013 · 6 revisions

This wiki is based on the structure present in BBB WIP branch

Backbone Boilerplate provide basic structure to help you get up and running with your tests.

First of all, you'll find three folder in ./test/. Each of those is a different test framework. You should choose the one better who better fits your taste (feel free to delete the other folders). Checkout Test frameworks section to know more.

Next, BBB uses the Karma test runner to easily launch your tests in different real browser and environments. To get an idea, just run grunt test in the root of a fresh BBB installation to run the example tests included.

Test frameworks

Three test frameworks are available by default: QUnit, Mocha and Jasmine.

QUnit

http://qunitjs.com/

QUnit is a TDD (Test driven development) framework maintained by the jQuery foundation. It has a great reputation among the community and have good documentation. It is really easy to get QUnit up and running.

It is mostly suited for browser testing, but some server implementation have been done. It is appreciated for its simplicity.

Mocha

http://visionmedia.github.io/mocha/

Mocha is a style agnostic (configurable as TDD or BDD) framework. It is mostly know in the Node.js world as it is developed by Express creator. Although, support in the browser is just as good as the others. It is often preferred for its very clean and declarative syntax, but is longer to get up and running from scratch.

Note that Mocha don't come with an Assertion library. By default BBB include Chai setted up with the expect syntax.

By default, BBB set

Jasmine

http://pivotal.github.io/jasmine/

Jasmine is a BDD (Behavior driven development) framework. It runs in both Node.js and the browser. Getting it up and running is very easy.

It have a very complete API (extra stuff like Spies are bundle in by default), but have a pretty bad asynchronous testing API. (We won't recommend Jasmine as our first choice)

Karma

Karma (via a Grunt task) is responsible for running your tests files in a real browser and report results directly on the terminal.

Configure

All karma settings are hold in the Gruntfile.js.

Every new test you create must be added to the test-runner.js files array. This file is located to the root of your testing framework folder (e.g. test/qunit/test-runner.js).

Run

Simply run grunt test in the root of your project to start the test suite.

Troubleshoot

If you have trouble running Karma, make sure the browser you're using is set up correctly in your console path. If you installed the browser out of the usual path (or if you're on windows 64bits), Karma won't find it in it's defaults search folder. It'll then need to be told where to find them. More information on the Karma documentation.