Test and Behavior Driven Development in JavaScript

Steven Parkes (smparkes.net llc)
Average rating: **...
(2.42, 12 ratings)

If you’re building a web application today, JavaScript is one of the most important foundations on which your application is built. There are a lot of libraries available to help you rapidly and easily use JavaScript to great effect. Testing that code, well, that’s a different matter.

Java has JUnit. Ruby has Test::Unit and RSpec. Python has unittest and Nose.

JavaScript has a number of unit test frameworks as well, but they see far less use than those seen in other languages. What JavaScript doesn’t have is an environment that makes it easy for a developer to write and run their tests without breaking their train of thought.

In Java you run Eclipse or ant. In Ruby you run rake or autotest. In python you run python or nose.

In JavaScript, you write your code, create an HTML fixture page to test that code, load that page in browser, click a few times, and look to see if the result looks right. Then you switch back to your editor, modify your code, bring the browser up again, hit browser refresh, click, look …

Or, more likely, you don’t. At least not very often.

And if you do run tests, you only run the tests you think you broke, rather than the ones you actually did break.

Much of this is because in JavaScript it has been harder to run tests than it has been to write them.

It’s now possible to do much better than edit/refresh/look/repeat. Borrowing heavily from best practices in other languages, it’s now possible to make JavaScript unit testing as easy as in, say, Ruby:

  • Without ever leaving your editor/IDE
  • Running tests without a browser
  • Running all tests in the browser quickly

In this talk we’ll walk through the process of developing/modifying a JavaScript browser-based application in a test-first manner, showing how every step can be automated for immediate feedback to the developer.

Highlights:

  • Running tests without an HTML fixture
  • Running tests against production HTML in situ
  • Test driven development with qunit
  • Behavior-driven development with jasmine
  • Using SpiderMonkey and Johnson to run JavaScript out of the browser fast
  • Using env.js to test within the browser environment without a browser
  • Using jazrb to run jasmine and qunit tests from the command line and get RSpec or JUnit output
  • Using wake to run all affected tests (and jslint!) on every save
  • Testing asynchronous JavaScript

Steven Parkes

smparkes.net llc

Steven Parkes is an independent software developer in Palo Alto, California. He has been involved in concurrent object oriented programming for many years. He currently specializes in highly-reliable and asynchronous web development.

  • Intel
  • Microsoft
  • Google
  • Facebook
  • Rackspace Hosting
  • (mt) Media Temple, Inc.
  • ActiveState
  • CommonPlaces
  • DB Relay
  • FireHost
  • GoDaddy
  • HP
  • HTSQL by Prometheus Research
  • Impetus Technologies Inc.
  • Infobright, Inc
  • JasperSoft
  • Kaltura
  • Marvell
  • Mashery
  • NorthScale, Inc.
  • Open Invention Network
  • OpSource
  • Oracle
  • Parallels
  • PayPal
  • Percona
  • Qualcomm Innovation Center, Inc.
  • Rhomobile
  • Schooner Information Technology
  • Silicon Mechanics
  • SourceGear
  • Symbian
  • VoltDB
  • WSO2
  • Linux Pro Magazine

Sponsorship Opportunities

For information on exhibition and sponsorship opportunities at the conference, contact Sharon Cordesse at scordesse@oreilly.com

Download the OSCON Sponsor/Exhibitor Prospectus

Media Partner Opportunities

Download the Media & Promotional Partner Brochure (PDF) for information on trade opportunities with O'Reilly conferences or contact mediapartners@ oreilly.com

Press and Media

For media-related inquiries, contact Maureen Jennings at maureen@oreilly.com

OSCON Newsletter

To stay abreast of conference news and to receive email notification when registration opens, please sign up for the OSCON Newsletter (login required)

OSCON 2.0 Ideas

Have an idea for OSCON to share? oscon-idea@oreilly.com

Contact Us

View a complete list of OSCON contacts