Skip to content

Instantly share code, notes, and snippets.

@uzzu
Last active December 10, 2015 20:58
Show Gist options
  • Save uzzu/4491370 to your computer and use it in GitHub Desktop.
Save uzzu/4491370 to your computer and use it in GitHub Desktop.
Stage reference in FlexUnit4 method A.
package
{
import flash.display.Stage;
import org.flexunit.asserts.assertNotNull;
import org.flexunit.assertThat;
import org.hamcrest.core.isA;
public class ATest
{
[Test]
public function referToTheStage():void
{
assertNotNull(ATestContext.virtualRoot.stage);
assertThat(ATestContext.virtualRoot.stage, isA(Stage));
}
}
}
package
{
import flash.display.DisplayObjectContainer;
public class ATestContext
{
public static var virtualRoot:DisplayObjectContainer;
public function ATestContext()
{
}
}
}
<?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;
public var core:FlexUnitCore;
public function onCreationComplete():void
{
var uiComponent:UIComponent = new UIComponent();
addChildAt(uiComponent, 0);
ATestContext.virtualRoot = uiComponent; // ATestContextは任意のクラス
core = new FlexUnitCore();
core.addListener(new UIListener(uiListener));
core.run(ATestSuite);
}
]]>
</mx:Script>
<flexUnitUIRunner:TestRunnerBase id="uiListener"
width="100%"
height="100%" />
</mx:Application>
package
{
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class ATestSuite
{
public var aTest:ATest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment