I’m doing a lot of work with JavaScript right now. I’ve been coding in sin, though: I haven’t done any regression testing. No unit tests, no functional tests. In part, I’ve just been lazy; but in my own defense, how do you unit test JavaScript?
Well, I’m thinking about collecting one of the most interesting pieces of code I’ve written for my latest project so that I can put in on SourceForge. I’ve never participated in Open Source development, but I’ve always wanted to. Releasing my code would be a small step into that world, and I’m eager to do it. But if I’m going to do that, a voice in my head insists, I can’t go releasing code that doesn’t have regression test coverage! So now, I have to figure out how to test in javascript.
My early forays into JavaScript testing have not been encouraging. A lot of pages point to JsUnit, which a lot of people seem to like. I confess I don’t like it, however. A few peeves:
- JsUnit feels clunky to me to open a browser page, type in a URL, and then get controls giving me bare stack traces in response to test failures. This is the age of Firebug, when information and insight can be integrated right into your browser–when you can step through code right in a browser frame or alter values in your code and instantly see what difference it makes. I wish there were something for testing that was as powerful and as easy to use as Firebug.
- It seems to have been abandoned, and maybe not in the best state. The only version available on JsUnit’s project site is over a year old now, and it’s an alpha version. I have a feeling something happened to stop work on the framework, and I’m not going to bitch at the developers for halting, because they were doing the work for free for people like me and because the reason for stopping could be personal. However, the fact remains JsUnit doesn’t seem to be keeping up with javascript and browser developments.
- It’s a port of jUnit, and this bothers me for philosophical reasons. At the risk of sounding petulant, jUnit is great for Java, but JavaScript ain’t Java, even despite the common letters in the names. Take a look at Wikipedia’s page for JavaScript, and check out the “Influenced by:” line. “Scheme, Self, Perl, Ruby.” Scheme used to be mentioned right in the beginning of the article, in fact. Scheme is a functional language. JavaScript, like Scheme, has lexical scoping. Of course, it also has prototype-based OO, like Self, and duck typing, like Ruby. It isn’t Java, and you ought to be able to find much more interesting and powerful ways to implement testing in such a language than with a straight port of jUnit’s Java code.
Anyway, I’ll see what I can make of JsUnit. I’m also going to go wade into some code to find out how the good folks behind Prototype implemented their testing. Maybe they made JsUnit work for them. But I’m hoping they did something clever so I can pay them the complement of stealing it. :-)