PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: Larry Marburger on June 11, 2008, 05:28:44



Title: PureMVC FlexUnit Testing
Post by: Larry Marburger on June 11, 2008, 05:28:44
I've been getting into some Flex 3 lately and have been loving both PureMVC Standard and MultiCore.  Without PureMVC, my Flex and Flash code would be (and is) a total mess.  So amazing job, PureMVC team.  I'd be lost without you.

Recently I picked up a copy of the Flex 3 Cookbook (http://www.amazon.com/Flex-Cookbook-Code-Recipes-Developers-Developer/dp/0596529856) and was drawn into the chapter on FlexUnit (http://code.google.com/p/as3flexunitlib/).  I played with some of the samples and immediately tried to apply it to the PureMVC Flex project I was working on.  All was well until I tried to write some simple unit tests for various asynchronous web service methods in a Proxy.  The FlexUnit way of dealing with asynchronous interactions is to use their addAsync() (http://code.ericfeminella.com/flexunit/docs/flexunit/framework/TestCase.html#addAsync()) factory method when attaching to an EventDispatcher with addEventListener().  Since PureMVC doesn't throw events (at least not to my knowledge -- it may behind the scenes), I had to hack something together.

And so the PureMVC FlexUnit Testing (http://code.google.com/p/puremvc-flexunit-testing/) project was born.

I made a detailed write-up (http://developmentastic.com/2008/06/09/flexunit-testing-puremvc-code/) for those interested laying out how it works and my thought process.  I did some research before going down this road but couldn't find anyone with a similar solution.  Maybe I'm blind or maybe I just wasn't asking the right questions.

I'd love to get some feedback from the PureMVC community.  Is this an acceptable way to go about unit testing asynchronous Notifications or is there something completely obvious I'm missing?


Title: Re: PureMVC FlexUnit Testing
Post by: Daniel on July 30, 2008, 06:00:02
Quick question: How can I get this to run the tests one after the other?  I've got a proxy that is a piece of media and obviously I can't execute multiple tests on it at the same time (i.e seek, next frame, etc.).


Title: Re: PureMVC FlexUnit Testing
Post by: puremvc on July 30, 2008, 07:08:50
If you're using MultiCore, you can get a new Facade instance for each test, so that will keep actions from the previous test from affecting the next one.

-=Cliff>


Title: Re: PureMVC FlexUnit Testing
Post by: Daniel on July 30, 2008, 08:56:47
Nope, not using Multicore.  Good suggestion though.


Title: Re: PureMVC FlexUnit Testing
Post by: sjlib on January 13, 2009, 01:25:37
When looking at this, it makes sense and is a nice way of 'short circuiting'? the framework for unit testing. The only thing I got hung up on is
:
// Manually register an observer on this proxy for the specified notification.
view.registerObserver(notificationName, new Observer(handler, this)); }
Larry admits this is not very clean. I'm not sure this can be done any other way. It seems registerObserver is only defined on IView. Is there in fact some other mechanism by which to register an Observer ? I'm guessing no.

Thanks.


Title: Re: PureMVC FlexUnit Testing
Post by: puremvc on January 14, 2009, 06:36:46
No, but the code seems fine.

-=Cliff>