|
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.
|
|
From: <luk...@us...> - 2006-10-05 19:07:59
|
Revision: 120
http://svn.sourceforge.net/asunit/?rev=120&view=rev
Author: lukebayes
Date: 2006-10-05 12:07:54 -0700 (Thu, 05 Oct 2006)
Log Message:
-----------
hooked up DEFAULT_TIMEOUT constant to async method timeout duration
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-10-05 19:03:10 UTC (rev 119)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-10-05 19:07:54 UTC (rev 120)
@@ -80,7 +80,7 @@
/**
* the name of the test case
*/
- protected static var DEFAULT_TIMEOUT:int = 500;
+ protected static const DEFAULT_TIMEOUT:int = 1000;
protected var fName:String;
protected var result:TestResult;
protected var testMethods:Array;
@@ -277,7 +277,7 @@
return context;
}
- protected function addAsync(handler:Function = null, duration:Number=1000):Function {
+ protected function addAsync(handler:Function = null, duration:Number=DEFAULT_TIMEOUT):Function {
if(handler == null) {
handler = function() {};
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2006-10-17 21:41:33
|
Revision: 128
http://svn.sourceforge.net/asunit/?rev=128&view=rev
Author: lukebayes
Date: 2006-10-17 14:41:30 -0700 (Tue, 17 Oct 2006)
Log Message:
-----------
Working on async methods in TestCase
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-10-12 06:21:07 UTC (rev 127)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-10-17 21:41:30 UTC (rev 128)
@@ -103,12 +103,12 @@
var methods:XMLList = description..method.(@name.match("^test"));
if(testMethod != null) {
testMethods = testMethod.split(", ").join(",").split(",");
+ if(testMethods.length == 1) {
+ runSingle = true;
+ }
} else {
setTestMethods(methods);
}
- if(testMethod != null) {
- runSingle = true;
- }
setName(className.toString());
}
@@ -186,28 +186,6 @@
isComplete = true;
dispatchEvent(new Event(Event.COMPLETE));
}
-
-/*
- try {
- while(itr.hasNext()) {
- name = String(itr.next());
- if(!runMethod(name)) {
- runCleanUp = false;
- break;
- }
- }
- }
- finally {
- if(runCleanUp) {
- if(!itr.hasNext()) {
- cleanUp();
- getResult().endTest(this);
- isComplete = true;
- dispatchEvent(new Event(Event.COMPLETE));
- }
- }
- }
-*/
}
private function getMethodIterator():Iterator {
@@ -230,11 +208,11 @@
methodIsAsynchronous = false;
this[methodName]();
}
- catch(e:AssertionFailedError) {
- getResult().addFailure(this, e);
+ catch(assertionFailedError:AssertionFailedError) {
+ getResult().addFailure(this, assertionFailedError);
}
- catch(ioe:Error) {
- getResult().addError(this, ioe);
+ catch(unknownError:Error) {
+ getResult().addError(this, unknownError);
}
finally {
if(!methodIsAsynchronous) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2006-10-23 19:25:14
|
Revision: 131
http://svn.sourceforge.net/asunit/?rev=131&view=rev
Author: lukebayes
Date: 2006-10-23 12:12:48 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Added bug fix to prevent multiple dispacthes to an async method from completing test execution more than once
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-10-19 18:33:04 UTC (rev 130)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-10-23 19:12:48 UTC (rev 131)
@@ -174,6 +174,9 @@
* throws Error
*/
public function runBare():void {
+ if(isComplete) {
+ return;
+ }
var name:String;
var itr:Iterator = getMethodIterator();
if(itr.hasNext()) {
@@ -301,6 +304,9 @@
}
protected function runTearDown():void {
+ if(isComplete) {
+ return;
+ }
if(!runSingle) {
tearDown();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2006-11-07 00:11:54
|
Revision: 133
http://svn.sourceforge.net/asunit/?rev=133&view=rev
Author: lukebayes
Date: 2006-11-06 16:11:50 -0800 (Mon, 06 Nov 2006)
Log Message:
-----------
Cleaned up LayoutManager code to avoid framework dependencies
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-11-07 00:01:21 UTC (rev 132)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-11-07 00:11:50 UTC (rev 133)
@@ -13,7 +13,7 @@
import flash.events.TimerEvent;
import flash.utils.setTimeout;
import flash.utils.clearTimeout;
- import mx.managers.LayoutManager;
+ import flash.utils.getDefinitionByName;
/**
* A test case defines the fixture to run multiple tests. To define a test case<br>
@@ -94,6 +94,7 @@
private var currentMethod:String;
private var runSingle:Boolean;
private var methodIterator:Iterator;
+ private var layoutManager:Object;
/**
* Constructs a test case with the given name.
@@ -111,7 +112,24 @@
setTestMethods(methods);
}
setName(className.toString());
+ resolveLayoutManager();
}
+
+ private function resolveLayoutManager():void {
+ // Avoid creating import dependencies on flex framework
+ // If you have the framework.swc in your classpath,
+ // the layout manager will be found, if not, a mcok
+ // will be used.
+ try {
+ var manager:Class = getDefinitionByName("mx.managers.LayoutManager") as Class;
+ layoutManager = manager["getInstance"]();
+ }
+ catch(e:Error) {
+ layoutManager = new Object();
+ layoutManager.resetAll = function():void {
+ }
+ }
+ }
/**
* Sets the name of a TestCase
@@ -310,7 +328,7 @@
}
if(!runSingle) {
tearDown();
- LayoutManager.getInstance().resetAll();
+ layoutManager.resetAll();
}
setTimeout(runBare, 5);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2007-01-29 23:09:38
|
Revision: 157
http://svn.sourceforge.net/asunit/?rev=157&view=rev
Author: lukebayes
Date: 2007-01-29 15:09:39 -0800 (Mon, 29 Jan 2007)
Log Message:
-----------
added more informative exception for removeChild when tearDown attempts to removeChild with a null child reference
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/TestCase.as
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2007-01-27 04:02:59 UTC (rev 156)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2007-01-29 23:09:39 UTC (rev 157)
@@ -338,6 +338,9 @@
}
protected function removeChild(child:DisplayObject):DisplayObject {
+ if(child == null) {
+ throw new IllegalOperationError("TestCase.removeChild must have non-null parameter child");
+ }
return getContext().removeChild(child);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2007-10-25 18:48:06
|
Revision: 173
http://asunit.svn.sourceforge.net/asunit/?rev=173&view=rev
Author: lukebayes
Date: 2007-10-25 11:48:07 -0700 (Thu, 25 Oct 2007)
Log Message:
-----------
Added support for addAsync in the setUp method
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/TestCase.as
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2007-10-11 18:46:45 UTC (rev 172)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2007-10-25 18:48:07 UTC (rev 173)
@@ -80,21 +80,24 @@
* @see TestSuite
*/
public class TestCase extends Assert implements Test {
- /**
- * the name of the test case
- */
- protected static const DEFAULT_TIMEOUT:int = 1000;
+ protected static const PRE_SET_UP:int = 0;
+ protected static const SET_UP:int = 1;
+ protected static const RUN_METHOD:int = 2;
+ protected static const TEAR_DOWN:int = 3;
+ protected static const DEFAULT_TIMEOUT:int = 1000;
protected var fName:String;
protected var result:TestResult;
protected var testMethods:Array;
protected var isComplete:Boolean;
protected var context:DisplayObjectContainer;
protected var methodIsAsynchronous:Boolean;
+ protected var setUpIsAsynchronous:Boolean;
protected var timeout:Timer;
private var currentMethod:String;
private var runSingle:Boolean;
private var methodIterator:Iterator;
private var layoutManager:Object;
+ private var currentState:int;
/**
* Constructs a test case with the given name.
@@ -203,6 +206,7 @@
var itr:Iterator = getMethodIterator();
if(itr.hasNext()) {
name = String(itr.next());
+ currentState = PRE_SET_UP;
runMethod(name);
}
else {
@@ -228,10 +232,19 @@
private function runMethod(methodName:String):void {
try {
- setUp();
+ methodIsAsynchronous = false;
+ if(currentState == PRE_SET_UP) {
+ currentState = SET_UP;
+ setUp(); // setUp may be async and change the state of methodIsAsynchronous
+ }
currentMethod = methodName;
- methodIsAsynchronous = false;
- this[methodName]();
+ if(!methodIsAsynchronous) {
+ currentState = RUN_METHOD;
+ this[methodName]();
+ }
+ else {
+ setUpIsAsynchronous = true;
+ }
}
catch(assertionFailedError:AssertionFailedError) {
getResult().addFailure(this, assertionFailedError);
@@ -312,7 +325,7 @@
context.getResult().addError(context, ioe);
}
finally {
- context.runTearDown();
+ context.asyncMethodComplete();
}
}
}
@@ -321,11 +334,21 @@
var context:TestCase = this;
return function(event:Event):void {
context.getResult().addError(context, new IllegalOperationError("TestCase.timeout (" + duration + "ms) exceeded on an asynchronous test method."));
- context.runTearDown();
+ context.asyncMethodComplete();
}
}
+
+ protected function asyncMethodComplete():void {
+ if(currentState == SET_UP) {
+ runMethod(currentMethod);
+ }
+ else if(currentState == RUN_METHOD) {
+ runTearDown();
+ }
+ }
protected function runTearDown():void {
+ currentState = TEAR_DOWN;
if(isComplete) {
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2007-11-16 18:15:33
|
Revision: 180
http://asunit.svn.sourceforge.net/asunit/?rev=180&view=rev
Author: lukebayes
Date: 2007-11-16 10:15:37 -0800 (Fri, 16 Nov 2007)
Log Message:
-----------
Change setUpIsAsynchronous from protected to private
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/TestCase.as
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2007-11-10 00:28:49 UTC (rev 179)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2007-11-16 18:15:37 UTC (rev 180)
@@ -91,8 +91,8 @@
protected var isComplete:Boolean;
protected var context:DisplayObjectContainer;
protected var methodIsAsynchronous:Boolean;
- protected var setUpIsAsynchronous:Boolean;
protected var timeout:Timer;
+ private var setUpIsAsynchronous:Boolean;
private var currentMethod:String;
private var runSingle:Boolean;
private var methodIterator:Iterator;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|