http://uzzu.github.com/blog/2013/01/09/stage-reference-in-flexunit4/
Last active
December 10, 2015 20:58
-
-
Save uzzu/4491795 to your computer and use it in GitHub Desktop.
Stage reference in FlexUnit4 method B.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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