Skip to content

Instantly share code, notes, and snippets.

@uzzu
Last active December 10, 2015 20:58
Show Gist options
  • Save uzzu/4491795 to your computer and use it in GitHub Desktop.
Save uzzu/4491795 to your computer and use it in GitHub Desktop.
Stage reference in FlexUnit4 method B.
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import org.flexunit.asserts.assertNotNull;
import org.flexunit.assertThat;
import org.flexunit.async.Async;
import org.fluint.uiImpersonation.UIImpersonator;
import org.hamcrest.core.isA;
public class BTest
{
public var container:DisplayObjectContainer;
[Before(async,ui)]
public function initialize():void
{
container = new Sprite();
Async.proceedOnEvent(this, container, Event.ADDED_TO_STAGE, 100);
UIImpersonator.addChild(container);
}
[After]
public function finalize():void
{
UIImpersonator.removeChildren();
container = null;
}
[Test]
public function referToTheStage():void
{
assertNotNull(container.stage);
assertThat(container.stage, isA(Stage));
}
}
}
<?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">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import org.flexunit.listeners.UIListener;
import org.flexunit.runner.FlexUnitCore;
import org.fluint.uiImpersonation.IVisualEnvironmentBuilder;
import org.fluint.uiImpersonation.VisualTestEnvironmentBuilder;
public var core:FlexUnitCore;
public function onCreationComplete():void
{
var uiComponent:UIComponent = new UIComponent();
addChild(uiComponent);
var testEnvironment:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance(uiComponent);
testEnvironment.buildVisualTestEnvironment();
core = new FlexUnitCore();
core.addListener(new UIListener(uiListener));
core.run(BTestSuite);
}
]]>
</mx:Script>
<flexUnitUIRunner:TestRunnerBase id="uiListener"
width="100%"
height="100%" />
</mx:Application>
package
{
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class BTestSuite
{
public var bTest:BTest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment