<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: Asyncronous test setup with FlexUnit</title>
	<atom:link href="http://eyefodder.com/2006/06/asyncronous_test_setup_with_fl.html/feed" rel="self" type="application/rss+xml" />
	<link>http://eyefodder.com/2006/06/asyncronous_test_setup_with_fl.html</link>
	<description></description>
	<lastBuildDate>Thu, 18 Sep 2014 13:13:44 +0000</lastBuildDate>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Paul BH</title>
		<link>http://eyefodder.com/2006/06/asyncronous_test_setup_with_fl.html#comment-7</link>
		<dc:creator><![CDATA[Paul BH]]></dc:creator>
		<pubDate>Mon, 14 Aug 2006 18:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://localhost:8888/?p=15#comment-7</guid>
		<description><![CDATA[Hi Kaleb - I guess I should have reposted on this, but I&#039;ve been in the middle of a project, so just haven&#039;t had a chance to...
I too found the same problem as you. So what I ended up doing was writing a helper function for a test case that needs external data. It is passed a callback function so that once the data is loaded, the callback is triggered which does all the asserts.  its probably easier to look at the code than to read my ramblings, so here goes:
&lt;pre&gt;
private static var userXML:XML;
private function loadAsyncData(f:Function):void{
if(userXML==null){
var helper:Function = addAsync(completeHandler,500,f);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, helper);
var request:URLRequest = new URLRequest(&lt;i&gt;yourURL&lt;/i&gt;);
loader.load(request);
}else{
f();
}
}
private function completeHandler(event:Event, f:Function):void {
var loader:URLLoader = URLLoader(event.target);
userXML = new XML(loader.data);
f();
}
&lt;/pre&gt;
So then when you want to run a test that needs this data, you would do it like this:
&lt;pre&gt;public function testCreatesValidAccount():void{
loadAsyncData(lazyCreatesValidAccount)
}
private function lazyCreatesValidAccount():void{
//stuff in here...
}
&lt;/pre&gt;
Hope this makes sense?
thx
PBH
]]></description>
		<content:encoded><![CDATA[<p>Hi Kaleb &#8211; I guess I should have reposted on this, but I&#8217;ve been in the middle of a project, so just haven&#8217;t had a chance to&#8230;<br />
I too found the same problem as you. So what I ended up doing was writing a helper function for a test case that needs external data. It is passed a callback function so that once the data is loaded, the callback is triggered which does all the asserts.  its probably easier to look at the code than to read my ramblings, so here goes:</p>
<pre>
private static var userXML:XML;
private function loadAsyncData(f:Function):void{
if(userXML==null){
var helper:Function = addAsync(completeHandler,500,f);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, helper);
var request:URLRequest = new URLRequest(<i>yourURL</i>);
loader.load(request);
}else{
f();
}
}
private function completeHandler(event:Event, f:Function):void {
var loader:URLLoader = URLLoader(event.target);
userXML = new XML(loader.data);
f();
}
</pre>
<p>So then when you want to run a test that needs this data, you would do it like this:</p>
<pre>public function testCreatesValidAccount():void{
loadAsyncData(lazyCreatesValidAccount)
}
private function lazyCreatesValidAccount():void{
//stuff in here...
}
</pre>
<p>Hope this makes sense?<br />
thx<br />
PBH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kaleb Pederson</title>
		<link>http://eyefodder.com/2006/06/asyncronous_test_setup_with_fl.html#comment-6</link>
		<dc:creator><![CDATA[Kaleb Pederson]]></dc:creator>
		<pubDate>Mon, 14 Aug 2006 18:03:28 +0000</pubDate>
		<guid isPermaLink="false">http://localhost:8888/?p=15#comment-6</guid>
		<description><![CDATA[Hi Paul!
Thanks for your documentation on the FlexUnit &quot;stuff&quot;.  I was trying to verify the async test setup and ran into some problems.  It turns out that although this successfully makes the runMiddle() run after any test setup, it doesn&#039;t stop the listener from believing that the event succeeded.
Here&#039;s some code that shows what I mean:
&lt;pre&gt;
package code
{
import flexunit.framework.TestCase;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AsyncTests extends TestCase
{
private var timer:Timer;
public override function runMiddle():void {}
public override function setUp():void {
timer = new Timer(5000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
timer.start();
}
private function onTimerComplete(e:TimerEvent):void {
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer = null;
super.runMiddle();
}
public function testShouldFail():void {
assertFalse(true);
}
public function testShouldSucceed():void {
assertTrue(true);
}
}
}
&lt;/pre&gt;
Obviously, the &#039;testShouldFail&#039; test should fail, but the listener shows that it succeeded, even though it generates a traceback after the test results have been displayed.
Please let me know if there is anything that I can do to help figure this out....
Thanks.
--Kaleb
]]></description>
		<content:encoded><![CDATA[<p>Hi Paul!<br />
Thanks for your documentation on the FlexUnit &#8220;stuff&#8221;.  I was trying to verify the async test setup and ran into some problems.  It turns out that although this successfully makes the runMiddle() run after any test setup, it doesn&#8217;t stop the listener from believing that the event succeeded.<br />
Here&#8217;s some code that shows what I mean:</p>
<pre>
package code
{
import flexunit.framework.TestCase;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AsyncTests extends TestCase
{
private var timer:Timer;
public override function runMiddle():void {}
public override function setUp():void {
timer = new Timer(5000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
timer.start();
}
private function onTimerComplete(e:TimerEvent):void {
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer = null;
super.runMiddle();
}
public function testShouldFail():void {
assertFalse(true);
}
public function testShouldSucceed():void {
assertTrue(true);
}
}
}
</pre>
<p>Obviously, the &#8216;testShouldFail&#8217; test should fail, but the listener shows that it succeeded, even though it generates a traceback after the test results have been displayed.<br />
Please let me know if there is anything that I can do to help figure this out&#8230;.<br />
Thanks.<br />
&#8211;Kaleb</p>
]]></content:encoded>
	</item>
</channel>
</rss>
