[Zope3-dev] Re: Zope3 JavaScript unittests

Shane Hathaway shane@zope.com
Wed, 11 Dec 2002 11:18:37 -0500


Godefroid Chapelle wrote:
> As you supposedly know, there has been work at Rotterdam with JavaScript 
> in the UI.
> 
> I am looking for opinions how to write unit tests for this JavaScript 
> code, if we want to integrate this testing with the whole test suite, 
> ... and other points I have not thought about.
> 
> I have the feeling that the JS code could grow quiet a lot if we really 
> intend to add all bells and whistles we have been speaking about.
> 
> I think we need to think about those tests before it gets a too big task 
> to integrate.
> 
> A first google search conducted me to :
> 
> http://www.edwardh.com/jsunit/
> 
> Are there people within the community with experience of this 
> framework... or another ?

My initial reaction was that it's hard to write unit tests against code 
like this.  But then I remembered that I thought the same thing of Zope 
about 2 years ago, and now we have about 2000 fully automated tests for 
both Zope 2 and Zope 3.  I've obviously been proven wrong, and I won't 
make the same mistake again. :-)

Start with the simple things.  The selection management functions in 
pdlib should be workable without any user interaction.  Then try sending 
an XML-RPC request and check the response.  You could manually construct 
an event object to pop up a context menu (I think there's a 
document.createEvent() method or somesuch).

FWIW, of all the software-related things I've learned in the past three 
years, automated testing is by far the most important lesson.  It can 
turn failure into success, and it's easy with a very high-level 
language.  If I taught computer programming, automated testing would be 
part of the very first lesson.  (Ok, maybe the second. :-) )

Shane