|
From: <luk...@us...> - 2006-09-20 21:21:44
|
Revision: 112
http://svn.sourceforge.net/asunit/?rev=112&view=rev
Author: lukebayes
Date: 2006-09-20 14:21:37 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
got async method working better
Modified Paths:
--------------
trunk/framework/as3/AsUnitTestRunner.as
trunk/framework/as3/asunit/framework/TestCase.as
Added Paths:
-----------
trunk/framework/as3/asunit/framework/TestCaseExample.as
Removed Paths:
-------------
trunk/framework/as3/asunit/AllTests.as
Modified: trunk/framework/as3/AsUnitTestRunner.as
===================================================================
--- trunk/framework/as3/AsUnitTestRunner.as 2006-09-20 18:50:50 UTC (rev 111)
+++ trunk/framework/as3/AsUnitTestRunner.as 2006-09-20 21:21:37 UTC (rev 112)
@@ -1,13 +1,13 @@
package {
+ import asunit.framework.TestCaseExample;
import asunit.textui.TestRunner;
- import asunit.framework.TestCaseTest;
import asunit.textui.TestRunnerTest;
public class AsUnitTestRunner extends TestRunner {
public function AsUnitTestRunner() {
- start(AllTests, null, TestRunner.SHOW_TRACE);
-// start(TestRunnerTest);
+// start(AllTests, null, TestRunner.SHOW_TRACE);
+ start(TestCaseExample);
}
}
}
Deleted: trunk/framework/as3/asunit/AllTests.as
===================================================================
--- trunk/framework/as3/asunit/AllTests.as 2006-09-20 18:50:50 UTC (rev 111)
+++ trunk/framework/as3/asunit/AllTests.as 2006-09-20 21:21:37 UTC (rev 112)
@@ -1,15 +0,0 @@
-package asunit {
- import asunit.framework.TestSuite;
- import asunit.framework.AllTests;
- import asunit.textui.AllTests;
- import asunit.util.AllTests;
-
- public class AllTests extends TestSuite {
-
- public function AllTests() {
- addTest(new asunit.framework.AllTests());
- addTest(new asunit.textui.AllTests());
- addTest(new asunit.util.AllTests());
- }
- }
-}
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2006-09-20 18:50:50 UTC (rev 111)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-09-20 21:21:37 UTC (rev 112)
@@ -79,7 +79,7 @@
/**
* the name of the test case
*/
- protected var DEFAULT_TIMEOUT:int = 500;
+ protected static var DEFAULT_TIMEOUT:int = 500;
protected var fName:String;
protected var result:TestResult;
protected var testMethods:Array;
@@ -277,10 +277,10 @@
return context;
}
- protected function addAsync(handler:Function):Function {
+ protected function addAsync(handler:Function, timeout:int=500):Function {
methodIsAsynchronous = true;
- var context:Object = this;
- asyncMethodTimeoutId = setTimeout(timeoutHandler, DEFAULT_TIMEOUT);
+ var context:TestCase = this;
+ asyncMethodTimeoutId = setTimeout(timeoutHandler, timeout);
return function(args:*):* {
try {
handler.apply(context, arguments);
@@ -289,10 +289,13 @@
context.result.addFailure(context, e);
}
catch(ioe:IllegalOperationError) {
+ trace('foo'); // this trace needs to be here?! Why?!
context.result.addError(context, ioe);
}
- context.methodIsAsynchronous = false;
- context.runBare();
+ finally {
+ context.methodIsAsynchronous = false;
+ context.runBare();
+ }
}
}
Added: trunk/framework/as3/asunit/framework/TestCaseExample.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCaseExample.as (rev 0)
+++ trunk/framework/as3/asunit/framework/TestCaseExample.as 2006-09-20 21:21:37 UTC (rev 112)
@@ -0,0 +1,77 @@
+package asunit.framework {
+ import asunit.framework.TestCase;
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.IEventDispatcher;
+ import flash.events.EventDispatcher;
+ import flash.utils.setTimeout;
+
+ // These should always end with Test, the example
+ // doesn't because we don't want TestSuites in this
+ // directory.
+ public class TestCaseExample extends TestCase {
+ private var date:Date;
+ private var sprite:Sprite;
+
+ // TestCase constructors must be implemented as follows
+ // so that we can execute a single method on them from
+ // the TestRunner
+ public function TestCaseExample(testMethod:String = null) {
+ super(testMethod);
+ }
+
+ // This method will be called before every test method
+ protected override function setUp():void {
+ date = new Date();
+// sprite = new Sprite();
+// addChild(sprite);
+ }
+
+ // This method will be called after every test method
+ // but only if we're executing the entire TestCase,
+ // the tearDown method won't be called if we're
+ // calling start(MyTestCase, "someMethod");
+ protected override function tearDown():void {
+// removeChild(sprite);
+// sprite = null;
+ date = null;
+ }
+
+ // This is auto-created by the XULUI and ensures that
+ // our objects are actually created as we expect.
+ public function testInstantiated():void {
+ assertTrue("Date instantiated", date is Date);
+// assertTrue("Sprite instantiated", sprite is Sprite);
+ }
+
+ // This is an example of a typical test method
+ public function testMonthGetterSetter():void {
+ date.month = 1;
+ assertEquals(1, date.month);
+ }
+
+ // This is an asynchronous test method
+ public function testAsyncFeature():void {
+ // create a new object that dispatches events...
+ var dispatcher:IEventDispatcher = new EventDispatcher();
+ // get a TestCase async event handler reference
+ var handler:Function = addAsync(changeHandler);
+ // subscribe to your event dispatcher using the returned handler
+ dispatcher.addEventListener(Event.CHANGE, handler);
+ // cause the event to be dispatched.
+// dispatcher.dispatchEvent(new Event(Event.CHANGE));
+ setTimeout(dispatcher.dispatchEvent, 200, new Event(Event.CHANGE));
+ }
+
+ protected function changeHandler(event:Event):void {
+ assertEquals(Event.CHANGE, event.type);
+ }
+
+ public function testAsyncFeatureTimeout():void {
+ var dispatcher:IEventDispatcher = new EventDispatcher();
+ var handler:Function = addAsync(changeHandler, 100);
+ dispatcher.addEventListener(Event.CHANGE, handler);
+ dispatcher.dispatchEvent(new Event(Event.CHANGE));
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|