|
From: <luk...@us...> - 2006-10-05 19:03:23
|
Revision: 119
http://svn.sourceforge.net/asunit/?rev=119&view=rev
Author: lukebayes
Date: 2006-10-05 12:03:10 -0700 (Thu, 05 Oct 2006)
Log Message:
-----------
Got async test case working much better within the context of a Flex Framework application
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/TestCase.as
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2006-09-21 18:19:08 UTC (rev 118)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-10-05 19:03:10 UTC (rev 119)
@@ -104,10 +104,10 @@
} else {
setTestMethods(methods);
}
- if(testMethods.length == 1) {
+ if(testMethod != null) {
runSingle = true;
}
- setName(className.toString());
+ setName(className.toString());
}
/**
@@ -174,20 +174,24 @@
public function runBare():void {
var name:String;
var itr:Iterator = getMethodIterator();
+ var runCleanUp:Boolean = true;
try {
while(itr.hasNext()) {
name = String(itr.next());
if(!runMethod(name)) {
+ runCleanUp = false;
break;
}
}
}
finally {
- if(!itr.hasNext() && !methodIsAsynchronous) {
- cleanUp();
- getResult().endTest(this);
- isComplete = true;
- dispatchEvent(new Event(Event.COMPLETE));
+ if(runCleanUp) {
+ if(!itr.hasNext()) {
+ cleanUp();
+ getResult().endTest(this);
+ isComplete = true;
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
}
}
}
@@ -207,23 +211,13 @@
private function runMethod(methodName:String):Boolean {
try {
- if(!isNaN(asyncMethodTimeoutId)) {
- clearTimeout(asyncMethodTimeoutId);
- asyncMethodTimeoutId = NaN;
- }
+// if(!isNaN(asyncMethodTimeoutId)) {
+// clearTimeout(asyncMethodTimeoutId);
+// asyncMethodTimeoutId = NaN;
+// }
setUp();
currentMethod = methodName;
- try {
- this[methodName]();
- if(methodIsAsynchronous) {
- return false;
- }
- }
- finally {
- if(!runSingle) {
- tearDown();
- }
- }
+ this[methodName]();
}
catch(e:AssertionFailedError) {
getResult().addFailure(this, e);
@@ -231,7 +225,12 @@
catch(ioe:Error) {
getResult().addError(this, ioe);
}
- return true;
+ finally {
+ if(!methodIsAsynchronous) {
+ runTearDown();
+ }
+ return !methodIsAsynchronous;
+ }
}
/**
@@ -278,10 +277,13 @@
return context;
}
- protected function addAsync(handler:Function, timeout:int=500):Function {
- this.methodIsAsynchronous = true;
+ protected function addAsync(handler:Function = null, duration:Number=1000):Function {
+ if(handler == null) {
+ handler = function() {};
+ }
var context:TestCase = this;
- this.asyncMethodTimeoutId = setTimeout(this.timeoutHandler, timeout, timeout);
+ context.methodIsAsynchronous = true;
+ asyncMethodTimeoutId = setTimeout(asyncTimeoutHandler, duration, duration);
return function(args:*):* {
clearTimeout(context.asyncMethodTimeoutId);
try {
@@ -297,17 +299,25 @@
}
finally {
context.methodIsAsynchronous = false;
+ context.runTearDown();
context.runBare();
}
}
}
- protected function timeoutHandler(timeout:Number):void {
- result.addError(this, new IllegalOperationError("TestCase.timeout (" + timeout + "ms) exceeded on an asynchronous test method."));
+ private function asyncTimeoutHandler(duration:Number):void {
+ result.addError(this, new IllegalOperationError("TestCase.timeout (" + duration + "ms) exceeded on an asynchronous test method."));
methodIsAsynchronous = false;
+ runTearDown();
runBare();
}
+ protected function runTearDown():void {
+ if(!runSingle) {
+ tearDown();
+ }
+ }
+
protected function addChild(child:DisplayObject):DisplayObject {
return getContext().addChild(child);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|