I’m in the process of working on, and improving, test suite support in TestSwarm (an upcoming project of mine). However, there isn’t a lot of information on which unit testing frameworks developers actually use to test their code (whereas there is more information on which JavaScript libraries are used).
It will be of great help to me if you could quickly fill out the question below. I will release the results of the survey as soon as possible. Thanks!
The poll is now closed. I’ve received 1853 responses and plan on writing a detailed blog post on the results. Thanks everyone!
More information on the frameworks listed above:
John Shimek (July 2, 2009 at 9:43 am)
At work we use JSUnit (which I voted for), but for my side projects, I am looking for something else. You list gives me choices:) Thanks.
Andy Atkinson (July 2, 2009 at 9:47 am)
I started watching blue-ridge on github yesterday and noticed it has almost 300 followers, however it is for Rails apps. Looks like it uses Screw.Unit and Env.js which you have in your list.
Randy Peterman (July 2, 2009 at 9:48 am)
I have been looking into doing this the last several days and have found NO useful tutorials (but would love to be pointed to one). I know almost nothing about practical implementation but am dying for code coverage so any feedback the community could provide would be greatly appreciated. Are there good books that I should read? Blogs worth following? Anything helps.
Greg (July 2, 2009 at 9:53 am)
Depends on the project. Sometimes I use one of those listed, sometimes I use one I made myself called suitejs (I released it here http://lemonlimesoftware.com/suitejs)
Stuardo -StR- Rodríguez (July 2, 2009 at 10:24 am)
I was looking for some automated tool to be added in my Cruise Control. The UT I’ve seen for JS are graphical oriented, so I need to run it by hand opening a browser, and watching the results…
Patrick Mueller (July 2, 2009 at 10:33 am)
Rather than “releasing” the results, can’t you just make the resulting spreadsheet that’s receiving the form posts world readable? Maybe that’s not an option …
Ron Derksen (July 2, 2009 at 10:50 am)
@Randy Peterman: I’m in the same situation. I would love to do some unit testing on my code, but I can’t find any tutorials that go beyond the basics and show how to apply unit testing to real life JS code. I would love such a tutorial as well.
Leonard Martin (July 2, 2009 at 10:59 am)
Can I add my voice to those of Randy and Ron. Having looked around for various resources about how to go about writing tests for anything beyond the most trivial code.
If there are any resources out there then I’d be interested to hear.
Dom Derrien (July 2, 2009 at 11:13 am)
I use JSUnit in conjunction with JSCoverage. A long time ago, I wrote a piece of glue for them to co-exist. Now Java developers coming to JavaScript can be easily productive, and I can monitor how safe is their production ;) I’m looking forward to integrating DOH and JSCoverage!
Luis Cipriani (July 2, 2009 at 11:14 am)
I use QUnit, it is simple, fast, really easy to use and to setup.
James H. (July 2, 2009 at 11:48 am)
I currently don’t test my JavaScript. I’m looking to change that shortly — I just hadn’t found a test suite I liked yet. Andy Atkinson mentioned blue-ridge which is something I really want to look into.
Dan Fabulich (July 2, 2009 at 12:21 pm)
You should specify which “JSUnit” you mean. There’s Hieatt’s JSUnit at jsunit.net and there’s Schaible’s JSUnit at http://jsunit.berlios.de/ … only Hieatt’s runs in-browser, but only Schaible’s can run headlessly.
John Resig (July 2, 2009 at 12:39 pm)
@Dan: I linked to the JSUnit.net one in the above post – I’ve never heard of the other JSUnit (although, I’m more concerned about test suites that are capable of running in a browser). Thanks for the heads-up, though!
mikeal (July 2, 2009 at 1:25 pm)
Windmill actually includes a pure javascript framework for functional testing and a JUnit API as well. This way you can run JUnit tests alongside windmill tests and get the advantage all the browse launchers and continuous integration features in windmill.
Frank Cohen (July 2, 2009 at 1:43 pm)
Hope you also include frameworks that make use of Javascript frameworks. For example, our own PushToTest TestMaker repurposes Selenium, Windmill, and other tests into functional tests, load and performance tests, and business service monitors. Details at http://www.pushtotest.com.
jon dogs (July 2, 2009 at 2:13 pm)
http://visionmedia.github.com/jspec/ is a new contender missing from the list.
kik (July 2, 2009 at 2:46 pm)
@jon dogs:
+1,
this is the one is use, btw.
Nicholas C. Zakas (July 2, 2009 at 3:01 pm)
I did a talk on Test-Driven Development using YUI Test not too long ago. You can find it at http://developer.yahoo.com/yui/yuitest/, hopefully that can get people started thinking about JavaScript unit testing. There was also a talk at last year’s Ajax Experience by Ted Husted who talked about integrating YUI Test into Hudson, and that video is here: http://www.bitpipe.com/detail/RES/1226146718_719.html
Matthew Eernisse (July 2, 2009 at 4:15 pm)
Here are the docs for Windmill’s JavaScript test framework:
http://trac.getwindmill.com/wiki/authoringtests#JavaScriptTests
The assert syntax is JSUnit-compatible. Write your tests in JavaScript, and you get to use all of Windmill’s browser-launching and reporting goodness.
Mr. Hericus (July 2, 2009 at 4:46 pm)
Our unit testing is mostly done using Selenium core, but there are also extensions to it from the Qooxdoo Simulator project. It bridges the gap between Selenium and the Qooxdoo Javascript library.
Sincerely,
Mr. Hericus
lrbabe (July 2, 2009 at 7:09 pm)
If you publish this survey only on your website you are likely to see a biaised result for Qunit. I hope it will be linked on ajaxian to allow for a better accuracy.
Simon (July 2, 2009 at 7:21 pm)
JSunit, but not entirely happy with it – I’ll be interested to see the results of this poll, see what others are doing. Also use Selenium, although not really as a “unit” testing tool, more for end-to-end tests of screen behavior.
Alejandro Rascón (July 2, 2009 at 11:52 pm)
QUnit! is easy to use,write less do more.
adios y buena suerte John.
Kent (July 3, 2009 at 3:35 am)
I wrote a library called QSTestLib (http://gitorious.org/qstestlib). Small and simple, easy to do data-driven testing, easy to flag expected failures and skip parts or whole of a test. Has an interface for logging results (plaintext, HTML and XML supported so far).
Jörn Zaefferer (July 3, 2009 at 8:43 am)
For those looking for resources on JS unit testing in general: The QUnit homepage lists various reference testsuites (http://docs.jquery.com/QUnit#Reference_testsuites). Following that, the approach to JS unit testing would be: Put your code into a resuable components, like jQuery plugins, then test the behaviour of those components. Thats what the reference testsuites do – none of them tests “page code”, its always in some reuseable module.
Jason Huggins (July 3, 2009 at 9:08 pm)
Not to be pedantic or anything.. Okay, never mind, I will be… As creator of Selenium Core, I should point out that Selenium is a functional/system/acceptance/demo/example/ui/smoke testing tool, not a *unit* test tool. Selenium is for driving the UI through single-page ajax or traditional multi-page workflows and making sure they work cross-browser. While unit testing tools are for testing headless pieces of code (functions, events, input/output) that either don’t touch the UI or abstract it away. Selenium should be “part of a complete breakfast” and used *in addition* to proper unit testing with a proper unit testing library. For everything beyond unit testing, knock yourself out with Selenium. So… with all that said.. if you removed the word “Unit” from the title of this poll, I’d have fewer problems with Selenium being on the list. I’d probably have zero problems if you started a separate poll for *functional* testing frameworks. But heh it’s your poll, and I love the spirit of finding out what people actually *use*, not just what is *sold*. :-) Keep kicking ass, John.
Simon (July 3, 2009 at 10:12 pm)
@Jason
Selenium is itself a fairly large body of Javascript – out of curiosity, what do you use for unit testing that?
David Waller (July 4, 2009 at 7:19 am)
Another +1 for JSpec mentioned above by jon dogs & kik. It can be run in a number of different ways, but I prefer the pure JavaScript-in-browser solution (beautifully demonstrated in the June issue of jsmag, http://www.jsmag.com/main.issues.description/id=21/).
Out of the frameworks I’ve tried (which admittedly doesn’t include all on John’s list), JSpec by far has the most readable syntax.
Kumar McMillan (July 4, 2009 at 4:46 pm)
fwiw, jsTestDriver (which I highly recommend!) is just a way to run JavaScript tests in many different browsers. For this reason, it now has a QUnit adapter: http://code.google.com/p/js-test-driver/wiki/QUnitAdapter This lets you run a QUnit test suite in multiple browsers simultaneously via the jsTestDriver command line.
James Carr (July 7, 2009 at 12:51 pm)
I’ve recently blogged about my experience with several different js testing frameworks here: http://blog.james-carr.org/category/tdd-javascript-series/
Overall, I really really like jspec… it has an interesting DSL for writing tests that is similar to rspec and has built in support for spies and stubs.
I am currently working on the js-test-driver codebase to allow using many different frameworks within it based on Kumar’s work.
Adam Gent (July 8, 2009 at 9:07 am)
I can’t find a nice doc on how to run browser based javascript unit tests under linux through a continous integration server. In other words I have always preferred headless test frameworks (no browser) because its so much easier for the CI server to run.
I know selenium and JSUnit have some different ways to handle running tests on other remote machines but I have never seen a write up on how to set everything up so that it works nicely with a CI server (Hudson in my case).
TJ Holowaychuk (July 9, 2009 at 10:10 am)
I too use JSpec obviously since I wrote it :) has a lot of potential for extending what exists through third party libraries as well.
Sleep Deprivation Ninja (July 11, 2009 at 11:10 am)
I’ve actually been using jQunit (http://code.google.com/p/jqunit/). Though, now I’m trying to switch over to JsTestDriver