Test-Driving Test-Driven Development with AsUnit
After a very worth while presentation by Joey Lott last night on Test-Driven Development using AsUnit I was sold.
Up until this morning I was doing unit testing on a very minor scale. I would make these empty FLAs and write some code to test all of the methods in class I wrote. While this method worked well, the testing FLAs weren’t very organized or consistent and have certainly cluttered my folders. My problem was I was lacking a formal approach.
So, I left Joey’s presentation with high hopes and excitement for trying out AsUnit on my own. This morning I was writing a new data model class and thought it was a perfect opportunity to take AsUnit for a test-drive.
The project I’m working on is in AS2 so I downloaded the MXP from the AsUnit web site and installed it to my Flash IDE. It went quickly with no problems. At first, it was hard to force myself to use AsUnit to test my class. I kept thinking, but this class is so easy, do I really need to test it? This is just going to add time that I don’t have. But, I was good and forced myself to learn to use it. I’m so glad I had. In less than an hour it became so natural to use. Once I had my test suites set up, any time I made a change to my class, running the tests gave me instant satisfaction and peace of mind that I was developing quality code.
My first failed test revealed that I had mistakenly typed “if (somevar = someval) {” which normally takes me a while to spot. (I can just see the ASP developers reading this are all nodding their heads up and down in acknowledgment). You see, in ASP “=” is used for both equality and assignment as apposed to ActionScript where it is just used for assignment. Since “if (somevar = someval) {” will always return true, I did not get a compile time error. Yet, I would have spent a long time trying to debug the problem. However, AsUnit came to the rescue because I was able to quickly identify the source of my problem by looking at which assertions were passing and which were failing. What a time saver!
To anyone on the fence about whether they should bother with unit testing or even Test-Driven Development, I highly recommend it. Stick out the initial learning curve until it becomes natural and you’ll be glad you did.
August 14th, 2007 at 1:34 pm
Hi there,
I am just getting started using asUnit, but I’m a little confused on how to use it. I have installed the MXP, but not sure where to go from there. If you could point me to some documentation on how to proceed that would be much appreciated.
Thanks,
Simon
August 14th, 2007 at 3:21 pm
Take a look at the breeze recording of Joey Lott’s presentation at:
https://admin.adobe.acrobat.com/_a200985228/p36722457/
You could also check out Tim Beynart’s introduction to ASUnit at:
http://www.flashcodersny.org/wordpress/?p=103
October 1st, 2007 at 2:50 pm
Are you still working with AsUnit or have you since dropped this in favour of any other programs?