Chapter 14. QUnit
QUnit is a powerful JavaScript test suite written by jQuery team member Jörn Zaefferer and used by many large open source projects (such as jQuery and Backbone.js) to test their code. It’s capable of testing both standard JavaScript code in the browser and code on the server side (where supported environments include Rhino, V8, and SpiderMonkey). This makes it a robust solution for a large number of use cases.
Quite a few Backbone.js contributors feel that QUnit is a better introductory framework for testing if you don’t wish to start off with Jasmine and BDD right away. As we’ll see later on in this chapter, QUnit can also be combined with third-party solutions such as SinonJS to produce an even more powerful testing solution supporting spies and mocks, which some say is preferable over Jasmine.
My personal recommendation is that it’s worth comparing both frameworks and opting for the solution that you feel the most comfortable with.
Getting Set Up
Luckily, getting QUnit set up is a fairly straightforward process that will take less than five minutes.
We first set up a testing environment composed of three files:
An HTML structure for displaying test results
The qunit.js file composing the testing framework
The qunit.css file for styling test results
The latter two of these can be downloaded from the QUnit website.
If you would prefer, you can use a hosted version of the QUnit source files for testing purposes. The hosted URLs can be found at https://github.com/jquery/qunit/ ...
Get Developing Backbone.js Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.