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 script.aculo.us and although the only documentation I could find was the PDF available at mir.aculo.us I thought I'd give it a go.

My only worry with using the script.aculo.us unit testing was its dependency on prototype and script.aculo.us (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 script.aculo.us 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 script.aculo.us 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=http://jjmgissbqxue.com/]jjmgissbqxue[/url], [link=http://rawoyelwzutd.com/]rawoyelwzutd[/link], http://dafiwtdswbws.com/

5. buy levitra 20mg - 1st Oct 2016 - 1:45 pm

http://levitra2016.us/#5821 buy levitra 20mg,

6. tretinoin cream cost - 1st Oct 2016 - 3:20 pm

http://buytretinoin.red/#5589 tretinoin cream,

7. retin-a - 1st Oct 2016 - 3:58 pm

http://retin-a.host/#1763 retin a,

8. cipro - 1st Oct 2016 - 4:22 pm

http://ciprofloxacin-500mg.us/#9709 ciprofloxacin 500 mg with out prescription,

9. albuterol sulfate - 1st Oct 2016 - 4:51 pm

http://albuterol-sulfate.gdn/#5817 albuterol,

10. motilium - 1st Oct 2016 - 5:31 pm

http://motilium-online.trade/#9538 motilium,

11. levitra - 1st Oct 2016 - 5:49 pm

http://cheaplevitra.bid/#6111 levitra,

12. buy tadacip 20 mg - 1st Oct 2016 - 6:09 pm

http://tadacip2016.us/#5485 tadacip 20 mg,

13. motrin - 1st Oct 2016 - 6:28 pm

http://motrinpm.eu/#2358 800 mg motrin,

14. singulair - 1st Oct 2016 - 6:58 pm

http://singulair10mg.bid/#3038 singulair 10mg price,

15. motrin - 1st Oct 2016 - 7:07 pm

http://buy-motrin.space/#9237 motrin,

16. cheap crestor - 1st Oct 2016 - 7:45 pm

http://generic-for-crestor.webcam/#1330 crestor,

17. safe place to buy viagra - 1st Oct 2016 - 8:04 pm

http://buy-viagra.stream/#6118 buy viagra,

18. cialis 5 mg - 2nd Oct 2016 - 10:46 am

http://cialis-5mg.bid/#8571 cialis,

19. abilify - 2nd Oct 2016 - 11:05 am

http://abilifygeneric.eu/#7623 abilify generic 15 mg,

20. baclofen 10 mg - 2nd Oct 2016 - 11:15 am

http://baclofen-10-mg.gdn/#7963 baclofen 10 mg,

21. buy buspar - 3rd Oct 2016 - 10:39 am

http://buspar.men/#7044 buy buspar,

Leave a comment

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