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.
July 30th, 2009 - 22:15
Blogged: Testing PureMVC code with FlexUnit http://bit.ly/VuKjh
This comment was originally posted on Twitter
July 31st, 2009 - 15:39
Testing PureMVC code with FlexUnit: http://snurl.com/oe69q
This comment was originally posted on Twitter
August 4th, 2009 - 13:25
Testing PureMVC code with FlexUnit http://bit.ly/VOQ1Y
This comment was originally posted on Twitter
August 4th, 2009 - 13:28
Testing PureMVC code with FlexUnit – http://bit.ly/Ra2hF
This comment was originally posted on Twitter
August 4th, 2009 - 13:37
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
February 5th, 2010 - 15:20
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
February 5th, 2010 - 20:26
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.
February 5th, 2010 - 21:03
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?