Unit Tests in JavaScript
by Pascal Opitz on May 31 2007, 17:52
I don’t know how many of you guys out there are seriously testing their javascript applications, and how you do approach tesing them.
I, until now, have been doing the good old step by step alert thing …
But my recent reading and the changes in my PHP development, where I’m using SimpleTest more and more, made me shop around for finding something similar for JavaScript.
The one I want to start using from now on to debug my scripts and trace their output, is called jsassertunit
A port of the xUnit framework (know from JUnit or PHPUnit) is JsUnit
Browsing around on the general subject of unit testing, I even came accross a test framework for XSLT. That left me quite surprised, and I wonder how many people really do use things like this. But then again, XSLT is a turing complete, so you can do potentially anything computable with it.
If anyone has suggestions or helpful examples on using unit tests in javascript, please drop a comment.
Also, I’d like to ask you, dear reader, to comment about your general testing practice and approach to debugging, not only JavaScript but everything you code.
Comments
Have you heard of Selenium? It’s a functional test suite for javascript which runs in many different browsers.
http://www.openqa.org/selenium/
I’ve only had a quick look at it, but it looks like it could be a powerful tool.
Erin.
by erin on May 31 2007, 16:28 #
by Pascal Opitz on May 31 2007, 17:47 #
With a javascript unit tester don’t you worry that you can only test some of the functionality? How do you test that the right behaviour has been bound to the events you intended?
xsltunit is great by the way, I used it 4 or 5 years ago when it was at version 0.1 to develop a pretty large xslt project test first, and it made the entire project feasible. It was easier to use once we’d written a stylesheet to convert the XML output into something similar to your typical command line xUnit output (i.e. dots).
by Graham on June 28 2007, 03:47 #
I think it’s worth adding that the console object of firebug provides an assert function … and also there’s a tool called firetest. Haven’t got the time to try it pout so far, but if I’ll have some JS work coming, then I’ll give that one a try for sure.
by Pascal Opitz on June 28 2007, 11:22 #