Saturday, April 11, 2009

Flex/AS Unit Tests

There is something I like about Rich Internet Application technologies. Although I have not looked at Silverlight yet, I find Flex quite appealing. Think it has something to do with nostalgia, taking me back to the good old days of rich client development. Having 'played around' with Flex to discover its capabilities, I now want to take it to the next stage and see if I could build something of production quality. It's clearly obvious this is possible from the applications beginning to emerge on the scene, but I have not yet seen a nice simple way of unit testing with Flex.

In particular, I am looking for the simplest way to mock or stub tests so that units can be isolated. I have been reading around a number of blogs and articles to see if there is a simple tried and trusted way of doing mocks, as with easymock or jmock in java land. Actionscript does not have dynamic proxy features of java which would permit runtime implementation of interfaces, so the current offerings out there look a little cumbersome.

Vaguely recalling that Ruby had a nice clean way of achieving this, I was wondering if a similar concept could be used for Actionscript, since it is also a dynamic language? Will do some more research.

Anyone out there have any ideas or experience on this subject?


Cory Wheeler said...

Hi Andrew,

Not sure if you ever found a solution for this, but in case you are still looking I stumbled across this article ( a while back. It looks like there has been a port of the Mockito framework for Flex developers ( mentioned it to Brad too, so you might check with him to see if he's used it with any success as I've not used it myself yet.

Take care,

Cory Wheeler

Andrew Walker said...

Cory, thanks for the comment. Yes, I was looking around for mocking frameworks for Actionscript a while back until Paul pointed out that I didn't need one!

Since Actionscript is a dynamic language, you can simply call a method on an object and if it understands the message, it will respond. Doing this, you can have your test class define a method called 'void doSomething()' and pass a reference to this into your code which then calls doSomething on your object.

Wish I had a better handle on dynamic languages, it really is so much simpler- with such power however comes responsibility - you've got to be careful not to shoot yourself in the foot.