Adventures With JavaScript Testing and mootools

I'm currently in the middle of writing a reusable little JavaScript utility, which I'll probably release when it's finished, for one of my many projects and I wanted to employ unit testing as part of the development process, as I believe in the benefits of it quite strongly.

However my previous experience with unit testing JavaScript haven't been the most pleasent, I have tried the most common nUnit variations for JS, the best of which was JSUnit. But I always found this a little cumbersome and difficult to use, however I had recently read about the unit testing available with and although the only documentation I could find was the PDF available at I thought I'd give it a go.

My only worry with using the unit testing was its dependency on prototype and (obviously) and now I've moved across to mootools for most things I thought there may be some clashes between prototype and mootools for this.

However with the current versions of each of those I managed to get everything working by changing only two lines in the unittest.js:

  1. Event.observe(td, 'click', function() ...


  1. $( td ).addEvent( 'click', function() ...

The unit testing framework is very fast (one of my tests performs 16 tests with 1904 assertions in about a second) and it does a great job of catching scripting and syntax errors and presenting those in a useful way without breaking the tests, which some frameworks I've used in different languages don't always handle too well.

The only let down is the current level of documentation, but if you've looked at unit testing in any other language this is almost the same and you can figure out what most of the assertions do from reading the PDF and looking at the source. The only minor niggle is the need to use the

  1. with( this ) {
  2.     ...
  3. }

syntax for all your assertions, I haven't found an explanation for why this is needed within each of the test methods and why it can't be hidden from the user, but you need it otherwise it won't work.

I haven't looked at using the functional tests available within yet as it's still at a very early stage and I'm not sure whether it's needed as I think I can do everything I need right now with unit tests. I hope to write more about specific examples of unit tests, e.g. complex ones which require DOM manipulation or user interaction etc., in JavaScript when I have some decent examples in place.


There have been 3 comments so far, join the discussion.

1. Javier Julio - 5th Mar 2007 - 2:36 pm

Any idea when you will be making this JavaScript library available? I’d be very interested to try it out.

2. Dave - 5th Mar 2007 - 3:24 pm

It’s kind of on hold at the moment, although I’ll probably get back on it within the next couple of weeks. At the moment it’s not nearly complete enough for me to be happy to release.

3. Javier Julio - 6th Mar 2007 - 4:29 pm

Thanks Dave for the response. Sorry as I realized I didn’t even ask about this JavaScript library of your’s. Is it a set of utility functions? A simple library for unit testing only?

4. qutlyyuk - 14th Aug 2016 - 7:31 pm

4UAd6f tihcvootplqp, [URL=]jjmgissbqxue[/url], [link=]rawoyelwzutd[/link],

Leave a comment

No HTML please, only textile. For code please use [lang]...[/lang] tags (e.g. [html]...[/html] for HTML)