Articles

AsUnit unit testing on flash package

One of the main things that need to be done to create any serious kind of software package, is making sure that it is tested to make qualitative statements about the code itself, be able to use it with confidence and to make sure it will continue to work when changes to the code are made.

For our package, one of the goals was to create high quality code, with unittesting in place to make sure the code will behave as expected.

Unittesting gives us a lot in return for writing the test code. It allows you to write code with confidence that it behaves as expected, makes refactoring easy and creates the first client of your code (the unittest itself). This will make your code more modular an reusable from the start, as it is made with multiple clients in mind just by using a unittest. It also provides you, the user of the code, a way to know that the code will work and has some quality control in place. In the case of the unittest being publicly availabe it also provides you with a way to see how the code can be used by serving as documentation. It really helps integration in writing larger software applications, as you know that the foundation has been thoroughly tested and components can be used together, doing what they do best, without worrying if the component does what it should do. You can therefore focus on the interaction of pieces of code that work, instead of trying to use pieces of code that together make up a larger body of code that is harder to debug.

Unittesting is on the level of testing classes and methods, as opposed to component testing, interface testing, performance testing or user acceptance testing, which takes place with different goals in mind and on a higher level than unittesting. We used the asunit framework, itself an opensource product, based on the xUnit family of unittesting frameworks from which it was ported, originally derived from a smalltalk framework written by Kent Beck, the founder of extreme programming and test driven development (write your test code first, then write your code).

Unittesting is done by writing code that tests your production code with assertions about the expected results.

assertEquals('3.45 rounded should be 3', Math.round(3.45), 3);

Now ain’t that easy ;)

a succesful unit test in flash

a succesful unit test

a failed unittest

a failed unittest

The testsuite (all tests written) will do a testrun on the system under test (SUT) and if everything works as expected, it produces an automated output that lets you know that everything passed the tests you wrote for your code. If an individual test failed, you will be notified by this. Automated testing is essential, as we do not want to live our coding life hunting bugs by looking at traces :)

Asunit is simple and fun to use and will really boost the quality of your code and is also a means to be very productive. Although this seems counterintuitive to many people, it turns out that being able to make changes to your code one place, while knowing that you will be informed when something breaks somewhere else, is a huge time saver because you will not have to hunt for bugs that get introduced when changing code. And this will happen…

The unittests themselves can be found in the repository, be sure to check it out, and give unittesting a try yourself!

an excellent book about unittesting, refactoring and patterns is xUnit Test Patterns: Refactoring Test Code.

1 Response to “AsUnit unit testing on flash package”


  1. 1 drupal developer

    Amazing, discovered your site on Ask.Pleased I finally tested it out. Unclear if it’s my Opera browser,but occasionally when I visit your blog, the fonts are very tiny? However, really like your blog and will check back.Bye

  1. 1 asunit modification for asynchronous testing at dpdk Open Source

Leave a Reply