I have an ActionScript Project and I have been running unit tests using the FlexUnit 4 integration in Flash Builder 4 Beta 2. These have been working great until I try to use UIImpersonator, which uses Flex classes and fails in my pure ActionScript project. (UIImpersonator works fine with a Flex Project.)
Since Flash Builder is for both Flex and ActionScript projects, I figured I would be able to use FlexUnit to equal extents. Is there an ActionScript project equivalent to UIImpersonator, or just a way to access the Stage?
Right now UIImpersonator has dependencies on UIComponent which is the reason it is only compiled into Flex projects. It is a goal to make this feature suitable for ActionScript projects. However, there will always be somethings that the Flex version can do that the ASOnly version cannot. For instance, binding and container based ideas.
We will add a feature request to Jira for this so you can track out progress,
Mike
http://www.uza.lt/codex/as3-global-object/
Actually scratch that suggestion for the moment.
I will work on a work around for you
Mike
Hey Michael,
I am able to compile now with the UIImpersonator in my ActionScript-only project, and I can add display objects to the UIImpersonator, but the DisplayObjectContainer that I am adding them to has a stage property with a value of null.
This DisplayObjectContainer is an instance of org.fluint.uiImpersonation.actionScript.ActionScriptVisualTestEnviron ment, and it has a protected stage property that I can't access. This stage property is passed to ActionScriptVisualTestEnvironment in the constructor, so I can't subclass it.
Maybe I've over-investigated, is there a simple way to access the stage? Shouldn't the UIImpersonator be on the stage when I call addChild()?
Thanks,
Gianni
Gianni,
Sorry, I haven't had a chance to document this yet, but, as you have seen, you can now call those UIImpersonator methods. There is one more requirement though to make this all work.
Before you run your tests in an AS only project, you need to create the VisualEnvironment and pass it a reference to the stage. Here is a quick example from my testing:
var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );
var spt:Sprite = new Sprite();
trace( UIImpersonator.numChildren );
UIImpersonator.addChild( spt );
trace( UIImpersonator.numChildren );
var core:FlexUnitCore = new FlexUnitCore();
core.addListener( new TraceListener() );
core.run( FlexUnitIn360 );
The *this* reference passed into the getInstance() method is the stage reference. This interface could change slightly in the future, but this is the best solution I have been able to find so far.
Mike
Thanks Mike.
I'm confused on where would I execute this code:
var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );
Currently, I only have the Unit Test classes in my TestSuite, and I run the Unit Tests with Flash Builder 4.
public class TestStuff
{
public function TestStuff()
{
}
[Test]
public function test():void{
// obviously passing "this" isn't going to help here...
var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );
}
}
Thanks,
Gianni
I found this BDD project page, which includes a stage access example:
Cuke4AS3 https://github.com/flashquartermaster/Cuke4AS3/
[EDIT]
After much research and complication, I ended up using a Singleton that provides a stage reference that was passed in from a `creationComplete` handler in my TestRunner.
=======TestRunner.mxml==========================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onCreationComplete()"
xmlns:flexUnitUIRunner="http://www.adobe.com/2009/flexUnitUIRunner"
styleName="flexUnitApplication"
layout="absolute" height="800" width="1000">
<mx:Script>
<![CDATA[
import org.flexunit.runner.FlexUnitCore;
private var core:FlexUnitCore;
public function onCreationComplete():void {
core = new FlexUnitCore();
core.addListener( new TraceListener() );
core.addListener( new UIListener( uiListener ));
new StageLocator(systemManager.stage);
core.run(MyTestSuite);
}
]]>
</mx:Script>
<mx:Style>
Application {
backgroundColor: #3872b2;
backgroundGradientColors: #3872b2, #0c1a3d;
backgroundGradientAlphas: 1, 1;
themeColor: #ffffff;
color: #444444;
fontFamily: "Myriad Pro Semibold";
fontSize: 12;
}
</mx:Style>
<flexUnitUIRunner:TestRunnerBase id="uiListener" width="100%" height="100%" />
</mx:Application>
=======StageLocator.as==========================================
package {
import flash.display.Stage;
public class StageLocator {
public static var instance:StageLocator;
public static var stage:Stage;
public function StageLocator ($stage:Stage) {
instance = this;
stage = $stage;
}
}
}
There is a gist here: https://gist.github.com/1094408 that explains how to access the stage from a pure ActionScript project.
North America
Europe, Middle East and Africa
Asia Pacific