*** Update 12/21/09: This is now an open source project available on Google Code! ***
I’ve been using ExtJS for almost a year now and I’ve built quite the library of custom extensions. As many JavaScript developers will tell you, the problem with having large code libraries is that (at some point) you have too much code to keep track of. Documentation is essential to maintaining organized code, but documentation doesn’t help you find a bug in 16,000 lines of code. Upon this realization, many developers begin researching a topic known as unit testing.
For most developers (those using Java and C#, among many others) unit testing is a fairly easy process to start. However JavaScript (in particular AJAX) doesn’t play nicely with unit tests. Not only do AJAX developers have to worry about variable scope (i.e. JavaScript’s wonderful global namespace), but we also have to consider connection/latency issues. It is incredibly hard to write reliable tests that have to sit and physically wait for a server response.
I’ve spent a lot of time researching the subject, and while I’m no expert I can clearly see that frameworks like YUI and jQuery have successfully engineered JavaScript/AJAX unit tests. But where does that leave ExtJS?
Up to this point, ExtJS developers have had two options:
- Use the YUI Test, qUnit or similar testing suites (none of which use the ExtJS libraries), or
- Complain that ExtJS has no unit testing suite
Anyone who attended the Ext Conference this year will remember how many people were asking about unit testing. . . it actually became really frustrating to hear the question asked so many times.
So while I’m certainly not an expert on the subject of unit testing, I’ve decided to actually do something about this problem. Today, I posted a thread on the ExtJS message board detailing my custom Unit Test class – which is built using ExtJS objects, and comes with a mediocre user interface. I’ve posted a demo of the ExtJS Unit Testing code on my own site.
My code is far from complete (I’ve posted as version 0.1), but I’m hoping over time to develop it into something as powerful as YUI Test. In the current version, I’ve got the following functions:
- generateGuid()
- assertEquals()
- assertNotEquals()
- assertUndefinedOrNull()
- assertNotUndefinedOrNull()
These methods tackle some very basic testing functionality, and I think they’re pretty self-explanitory. The next step will be attempting to test ExtJS objects and their extensions.