Testing PureMVC code with FlexUnit
The PureMVC FlexUnit Testing project is already quite old (last update was June 2008), but I just discovered it because I am currently working on a big Adobe AIR project that currently does not have a User Interface yet. We use the PureMVC framework for most of our bigger applications, and because it depends on Notifications it’s not that easy to Unit Test. Proxies don’t return results synchronously, but send notifications with the result in the body.
Well this small library helps connecting your PureMVC implementation code to the FlexUnit framework. The following example code shows the code for a Test Class for a DataProxy that has a method getSomeData(). As you can see, you need to write some code to access the facade, proxy, … but it’s all pretty straight forward.
{
import net.hufkens.example.ApplicationFacade;
import net.hufkens.example.config.ApplicationNotifications;
import net.hufkens.example.model.DataProxy;
import com.andculture.puremvcflexunittesting.*;
import org.puremvc.as3.core.View;
import org.puremvc.as3.interfaces.IView;
public class DataProxyTest extends PureMVCTestCase
{
private var timeout:int = 0;
public function DataProxyTest(methodName:String=null)
{
super(methodName);
}
protected function get facade():ApplicationFacade
{
return ApplicationFacade.getInstance();
}
public override function setUp():void
{
facade.registerProxy(new DataProxy());
}
protected function get proxy():DataProxy
{
var proxy:DataProxy =
DataProxy(facade.retrieveProxy(DataProxy.NAME));
return proxy;
}
protected function get view():IView
{
return View.getInstance() as IView;
}
public function testGetSomeData():void
{
registerObserver(view, proxy,
ApplicationNotifications.GET_SOME_DATA_DONE,
response, timeout);
proxy.getSomeData();
}
private function response(e:PureMVCNotificationEvent):void
{
assertTrue("data is not available",
e.notification.getBody().data.length>0);
}
}
}
It worked great for this project. I hope it will still be supported for Flex 4 so we can use the built-in unit testing features of Flash Builder.
Make sure you checkout the latest version from Google Code, because the swc file has an issue with multicore namespaces. The latest version in svn works fine.
8 Responses to Testing PureMVC code with FlexUnit
Leave a Reply Cancel reply
Lifestream
-
Checking out CocoaPods - an Objective-C library manager > https://t.co/xdLU5OgO— February 1st via Twitter
-
Finally found some time to dive into iOS5 Storyboarding.— February 1st via Twitter
-
RT @robbedoes: Fun to watch: an interview w/ the sound designer of Angry Birds: http://t.co/lDARIGbB— February 1st via Twitter
-
@wuotr Also, check this out: Flood Fill > http://t.co/SpweLK0N ;)— January 30th via Twitter
-
Love it! Timesaver++ CocosBuilder, a tool for graphically laying out sprites, layers and scenes for @cocos2d > http://t.co/Jrb8233D— January 30th via Twitter
-
RT @rwenderlich: Awesome list of Cocos2D source code projects, extensions and code from @iuridium: http://t.co/ovwLYhCv— January 29th via Twitter
-
Moo! @ Kinderboerderij kiewit http://t.co/tYBlLsvH— January 29th via Twitter
-
I've been doing my epic chores and just leveled-up. I'm a Level 8 Well-groomed Clansman now! #EpicWinApp— January 27th via Twitter
-





Blogged: Testing PureMVC code with FlexUnit http://bit.ly/VuKjh
This comment was originally posted on Twitter
Testing PureMVC code with FlexUnit: http://snurl.com/oe69q
This comment was originally posted on Twitter
Testing PureMVC code with FlexUnit http://bit.ly/VOQ1Y
This comment was originally posted on Twitter
Testing PureMVC code with FlexUnit – http://bit.ly/Ra2hF
This comment was originally posted on Twitter
Testing PureMVC code with FlexUnit http://bit.ly/VOQ1Y (via @flashtuts) @piercer this is one for you I guess.
This comment was originally posted on Twitter
Hi there,
Thank your for this great article! A quick question here, how do you add your PureMVCTestCase to your TestSuite. It gives me a compiling error… I want to be able to use testrunner.
Many thanks
Mo
Hi there
I have got the same issues with multicore namespaces. How do I get the latest version on svn? Could you please help me?
Thanks
M.
Hi,
This is an article from last year, and the code above uses the trunk source code from the Google code svn. You can checkout the source from svn using an svn client like TortoiseSVN or the Subclipse plugin for Flex Builder.
What exactly is the error you get?