Testing Javascript

Javascript is of pivotal importance to a modern web application. Page behavior done with Javascript is often requisite of client acceptance. So why don’t we test our Javascript with the same diligence as we do our server side application code?

The biggest barrier standing in the way of testing Javascript seems to be the initial entry. In Ruby on Rails, we get provisions for testing virtually for free. Test::Unit is built into Rails, and other tools like rspec and rcov are easy to install. Javascript testing does not have the same pervasiveness, and as a result there are few tools out there to help us get started.

I recently wanted to use Ryan Johnson’s Event.Behavior in a personal project of mine, but as the library is untested if I use it as is I will have no confidence in the behavior of the application. Check back here over the next couple weeks as I’ll be working on a Javascript centric Rails app and I will be posting what I hope to be a how-to guide to get started testing Javascript in Rails painlessly.

2 Responses to “Testing Javascript”

Angelo Mandato - December 1st, 2007 at 01:52 PM

The best place to test javascript is in the browsers. Unfortunately, what works in Firefox may not work in IE or Opera. This makes it nearly impossible to find decent debugging tools in the development/editor environment. I recommend debugging Javascript with the Firebug Firefox add-on. https://addons.mozilla.org/en-US/firefox/addon/1843 It will encourage you to keep your Javascript in manageable .js files and to turn off caching/temporary internet files in your browsers while debugging. I've been told that the Eclipse IDE has a pretty good Javascript debugger. That may be another resource to check out.

Ehren Murdick - December 17th, 2007 at 02:07 PM

Specifically what I'm talking about here is automated testing. More than just opening the page in a browser and clicking to make sure everything functions properly, a test suite that actually executed every line of code would be very useful. Sorry for the delay, I'm going to be writing the full post this week if it kills me.

Sorry, comments are closed for this article.