The Blog

May 8, 2008

Flex Is (Not) Mocking Me 

by Maxim Porges @ 9:42 PM | Link | Feedback (2)

Having recently rekindled my inner Test Nazi after getting back in to coding full time and learning dpuint, I've been rather disappointed to find that there is no easy way to mock objects in Flex for unit testing. I was able to find a Proxy-based mock framework for AS3 that looked pretty mature, but you can't pass mock objects in to methods since the compiler notices that they are not of the appropriate type expected by the receiving method and complains.

Even after concocting an abundance of attempts to trick the compiler in to accepting my mocks, they were all met with runtime errors. Bah!

Seems like the only way to get true mocking behavior with the ability to pass a mock object in as a method argument and see it fly is to extend a class/implement an interface, which obviously licks balls.

If anybody has any bright ideas to the contrary, please let me know. I have been able to get pretty good test coverage without mocks, but would love to get through that final mile without having to resort to extending classes. Perhaps Adobe could cover this in Flex 4 for me along with all the other cool stuff they have lined up?