Before I jump into how exactly you can perform super fast and easy JS testing, let me give you some background on the problem.
Javascript is a finicky language (Some people even hesitate to call it a language). And it can easily grow and become a horrible and complicated beast, incapable of being tamed once let loose. And testing it is a nightmare. Once you have decided on a framework (of which there are a dime a dozen), you then have to set it up to run just right. You need to set it up to actually run your tests. Then you have to figure out how to run it in a continuous integration environment. Maybe even run it in headless mode. And everyone solves it in their own ways.
But the biggest problem I have with most of these frameworks is that executing the tests usually requires a context switch. By that, I mean to run a JSUnit test, you end up usually having to open the browser, browse to a particular url or html page which then runs the test. Then you have to look at the results there, and then come back to your editor to either proceed further or fix your tests. Works, but really slows down development.
In java, all it takes is to click the run button in your IDE to run your tests. You get instant feedback, a green / red bar and details on which tests passed and failed and at what line. No context switch, you can get it to run at every save, and proceed on your merry way. Till now, this was not possible with Javascript.
But now, we have JS Test Driver. My colleagues Jeremie and Misko ended up running into some of the issues I outlined above, and decided that going along with the flow was simply unacceptable. So they created a JS Testing framework which solves these very things. You can capture any browser on any machine, and when you tell it to run tests, it will go ahead and execute them on all these browsers and return you the results in your client. And its blazing fast. I am talking milliseconds to run 100 odd tests. And you can tell it to rerun your tests at each save. All within the comforts of your IDE. AndĀ over the last three weeks, I have been working on the eclipse plugin for JS Test Driver, and its now at the point where its in a decent working condition.
The plugin allows you to, from within Eclipse, start the JS Test Driver server, capture some browsers, and then run your tests. You get pretty icons telling you what browsers were captured, the state of the server, the state of the tests. It allows you to filter and show only failures, rerun your last launch configuration, even setup the paths to your browsers so you can launch it all from the safety of eclipse. And as you can see, its super fast. Some 100 odd tests in less than 10 ms. If thats not fast, I don’t know what is.
For more details on JS Test Driver, visit its Google Code website and see how you can use it in your next project and even integrate it into a continuous integration. Misko talks a little bit more about the motivations behind writing it on his Yet Another JS Testing Framework post. To try out the plugin for yourselves, go add the following update site to eclipse : http://js-test-driver.googlecode.com/svn/update/. For all you IntelliJ fanatics, there is something similar in the works.

#1 by Karl O'Keeffe on August 13th, 2009
Do you know if this plugin will work with Aptana?
I’m currently using Aptana for my Javascript development, but I’m having trouble installing the JS Test Driver plugin.
I have installed the plugin, but it doesn’t show up in the Window > Show View > Other menu, or the Preferences pane.
Any ideas?
Thanks,
Karl
#2 by Toni on August 13th, 2009
Thanks! I was excited to see the plugin codes in SVN earlier this week as I discovered JsTestDriver. I already have a bunch of js unit tests in qunit compatible format running on top of rhino + env.js and I’m planning on making them run on top of JsTestDriver instead, with the QUnitAdapter. Looks really promising.
The plugin looks great, but the output of failed tests looks quite garbled. Basically JSON with all the escape characters.
Would it also be possible to make the file names clickable in the stack trace, as Firefox reports the file name and line number, so you could get directly to the failed source file and line.
The message box contents could also be updated to give the proper output on single click of the tests instead of current double click. And maybe if the focus is on a module name or the line identifying the browser the output could contain all log outputs for all tests in the module/all tests.
Great stuff! I’m waiting for updates!
#3 by Toni on August 13th, 2009
Oh, and forgot to say that the update site url on the project page is wrong, there’s and extra ‘*’.
#4 by Shyam on August 13th, 2009
I haven’t tried with Aptana, I have only tried with the inbuilt text editor and the web development suite that comes with Eclipse. I can try it out. In the meantime, if you can open your error log and send me any errors that JS Test Driver might have caused, that would be great. Just email it to me.
#5 by Shyam on August 13th, 2009
Yeah, the output formatting is one thing I need to fix. The problem with click and jump to file is actually a much harder one that it seems, in that people may name their JS files and the name of the test cases differently, in which case we would actually have to parse each and every JS file to find which editor window to open. Not too hard, but will have to give it a try. Would be great if you could file these in the Issues for the Google code project page, along with an eclipse label.
And fixed the update url, thanks for that.
#6 by Karl O'Keeffe on August 25th, 2009
Nothing shows up in the Aptana error logs I’m afraid, it just doesn’t seem to know the plugin exists.
I’ve moved to using Eclipse, and the plugin works fine.
I haven’t been able to work out how to run the tests on every save. Any ideas?
#7 by Varun on February 10th, 2010
Hi,
I installed the plugin in eclipse Galileo yesterday (the latest stable release) . Although, it installed without any issues and i can see it installed through the Help window. there is no js ts driver “view”. No trace of any change to eclipse. What is happening?