Unit Testing JavaScript With JsTestDriver
I've been experimenting with a new tool that was released open source recently called JsTestDriver
It's a tool that makes unit testing JavaScript simultaneously on many browsers from the command line very easy for the developer. Actually, there aren't many other tools like it that I know of. It also provides hooks for continuous integration (e.g. Xunit output) and is designed to help you run all unit tests when you click the save button in your code editor.
Here are some features it provides that I thought were nice:
- The browser environment is persistent. You don't deal with URLs so functional / system testing is not possible, just unit testing. This is by design because it is thus very fast to run tests; the runner only has to reload the scripts that have changed by modified timestamp. Instead of URLs and html, you just edit one config file in YAML to say which scripts to load and you write all tests in JavaScript.
- A simple JUnit class in JavaScript is provided. It has setUp / tearDown, assertEquals, everything you'd expect
- You run your tests from a java jar on the command line. It's fast and easy.
- Connecting multiple browsers is very straight forward. You just open a magic URL like http://127.0.0.1:4224/capture/ and the browser becomes a worker to your command line test runner. This makes farming out your browsers to multiple servers on other operating systems very easy.
- Tracebacks, whee! Errors and command line output is decent.
- jquery 1.3.2 is provided. You have to be careful to not include your own version though since reloading jquery can cause
$(document).ready(fn)to stop working and probably other cache-related errors. - You can select tests to run on the command line by their JavaScript object name.
- The DOM is actually reset before each test which is convenient. You can add elements in your setUp() if you need to like
$("body").add("div").attr("id","foo"). See Manipulating The DOM for more info. - You can use
assertExpects(n)to help make sure that assertions in callbacks are actually made. I was never a huge fan of counting asserts in tests but this works pretty well as a sanity measure.

Re: Unit Testing JavaScript With JsTestDriver
posted by Misko Hevery on Saturday Jun 13th, 2009 at 12:37a.m.
Glad you like JsTestDriver and thanks for a nice write up.
Re
posted by Ellen19 on Tuesday Feb 2nd, 2010 at 7:01p.m.
I realy like your distinguished text! Could you accomplish the research essay as example? Because I know that an experienced essay writing service would accomplish well researched essays of superior quality.
Re: Unit Testing JavaScript With JsTestDriver
posted by Casino Training on Friday Feb 12th, 2010 at 10:50p.m.
Thanks a lot for sharing this. GTAC is my my all-time favorite conference too, if there is just one conference on the planet which I can attend ever, GTAC would be the one for sure.I just cant wait to get the videos online.. Please provide me as soon a possible...Testing using a JavaScript is real a good idea because..it helps in integrated system and integrated testing becomes easy due to module and unit testing..
Re: Unit Testing JavaScript With JsTestDriver
posted by paper writers on Saturday Feb 20th, 2010 at 1:33p.m.
It's potentially hard operation for me...=/
Re: Unit Testing JavaScript With JsTestDriver
posted by jordan shoes on Monday Mar 1st, 2010 at 1:53a.m.
Thank you for your sharing.
Re: Unit Testing JavaScript With JsTestDriver
posted by dentists Staffordshire on Thursday Mar 11th, 2010 at 12:25p.m.
I am really happy for published this post appear in this site.This site is more valuable to me. I visit this site and read this post.