|
From: <luk...@us...> - 2006-09-19 20:35:14
|
Revision: 98
http://svn.sourceforge.net/asunit/?rev=98&view=rev
Author: lukebayes
Date: 2006-09-19 13:35:05 -0700 (Tue, 19 Sep 2006)
Log Message:
-----------
Working on async test methods
Modified Paths:
--------------
trunk/framework/as3/AsUnitTestRunner.as
trunk/framework/as3/asunit/framework/Assert.as
trunk/framework/as3/asunit/framework/TestCase.as
trunk/framework/as3/asunit/framework/TestResult.as
trunk/framework/as3/asunit/textui/TestRunnerTest.as
trunk/framework/as3/asunit/textui/TestRunnerTestCaseMock.as
Modified: trunk/framework/as3/AsUnitTestRunner.as
===================================================================
--- trunk/framework/as3/AsUnitTestRunner.as 2006-09-19 16:57:15 UTC (rev 97)
+++ trunk/framework/as3/AsUnitTestRunner.as 2006-09-19 20:35:05 UTC (rev 98)
@@ -1,12 +1,13 @@
package {
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(TestCaseTest, "testAsyncMethod");
+// start(TestRunnerTest);
}
}
}
Modified: trunk/framework/as3/asunit/framework/Assert.as
===================================================================
--- trunk/framework/as3/asunit/framework/Assert.as 2006-09-19 16:57:15 UTC (rev 97)
+++ trunk/framework/as3/asunit/framework/Assert.as 2006-09-19 20:35:05 UTC (rev 98)
@@ -2,12 +2,13 @@
import flash.errors.IllegalOperationError;
import asunit.errors.AssertionFailedError;
+ import flash.utils.Proxy;
/**
* A set of assert methods. Messages are only displayed when an assert fails.
*/
- public class Assert {
+ public class Assert extends Proxy {
/**
* Protect constructor since it is a static only class
*/
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2006-09-19 16:57:15 UTC (rev 97)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-09-19 20:35:05 UTC (rev 98)
@@ -5,7 +5,13 @@
import flash.display.DisplayObjectContainer;
import flash.errors.IllegalOperationError;
import flash.utils.describeType;
+ import asunit.util.Iterator;
+ import asunit.util.ArrayIterator;
+ import flash.net.getClassByAlias;
+ import flash.utils.setTimeout;
+ import flash.utils.flash_proxy;
+ use namespace flash_proxy;
/**
* A test case defines the fixture to run multiple tests. To define a test case<br>
* 1) implement a subclass of TestCase<br>
@@ -70,7 +76,6 @@
* @see TestResult
* @see TestSuite
*/
-
public class TestCase extends Assert implements Test {
/**
* the name of the test case
@@ -82,6 +87,7 @@
protected var context:DisplayObjectContainer;
private var currentMethod:String;
private var runSingle:Boolean;
+ private var methodIterator:Iterator;
/**
@@ -111,9 +117,25 @@
protected function setTestMethods(methodNodes:XMLList):void {
testMethods = new Array();
var methodNames:Object = methodNodes.@name;
+ var completeMethods:Array = new Array();
+ var name:String;
for each(var item:Object in methodNames) {
- testMethods.push(item.toString());
+ name = item.toString();
+ if(name.match(/Complete$/)) {
+ completeMethods.push(name);
+ swapCompleteMethod(name);
+ }
+ else {
+ testMethods.push(name);
+ }
}
+ for each(name in completeMethods) {
+ var index:int = name.indexOf("Complete");
+ var baseName:String = name.substr(0, index);
+ if(testMethods.indexOf(baseName) == -1) {
+ testMethods.push(name);
+ }
+ }
}
/**
@@ -161,28 +183,35 @@
* throws Error
*/
public function runBare():void {
- var methods:Array = testMethods;
+ var name:String;
+ var itr:Iterator = getMethodIterator();
try {
- for each(var name:String in methods) {
- try {
- runMethod(name);
+ while(itr.hasNext()) {
+ name = String(itr.next());
+ trace("itrating with: " + getName() + "." + name);
+ if(!runMethod(name)) {
+ trace("RETURNING ON : " + name);
+ break;
}
- catch(e:AssertionFailedError) {
- result.addFailure(this, e);
- }
- catch(ioe:Error) {
- result.addError(this, ioe);
- }
}
}
finally {
if(!runSingle) {
cleanUp();
+ if(!itr.hasNext()) {
+ result.endTest(this);
+ isComplete = true;
+ }
}
}
-
- isComplete = true;
}
+
+ private function getMethodIterator():Iterator {
+ if(methodIterator == null) {
+ methodIterator = new ArrayIterator(testMethods);
+ }
+ return methodIterator;
+ }
// Override this method in Asynchronous test cases
// or any other time you want to perform additional
@@ -190,19 +219,57 @@
protected function cleanUp():void {
}
- private function runMethod(methodName:String):void {
- setUp();
- currentMethod = methodName;
+// override flash_proxy function hasProperty(name:*):Boolean {
+// return (this[name] != undefined);
+// }
+
+// override flash_proxy function getProperty(name:*):* {
+// return this[name];
+// }
+
+ private function runMethod(methodName:String):Boolean {
try {
- this[methodName]();
- }
- finally {
- if(!runSingle) {
- tearDown();
+ setUp();
+ currentMethod = methodName;
+ try {
+// var ns:Namespace = flash_proxy;
+// if(this.flash_proxy::hasProperty(methodName + "Complete")) {
+// trace("HAS PROP : " + methodName);
+// }
+// if(this[methodName + "Complete"] != null) {
+// if(this.hasOwnProperty(methodName + "Complete")) {
+// setTimeout(this[methodName], 1);
+// return false;
+// }
+ this[methodName]();
}
+ finally {
+ if(!runSingle) {
+ tearDown();
+ }
+ }
}
+ catch(e:AssertionFailedError) {
+ result.addFailure(this, e);
+ }
+ catch(ioe:Error) {
+ result.addError(this, ioe);
+ }
+ return true;
}
+ private function swapCompleteMethod(name:String):void {
+ trace("swapping complete method with: " + name);
+ var obj:Object = new Object();
+ obj[name] = this[name];
+// this[name] = defaultCompleteMethod;
+// this.prototype["__" + name] = this.prototype[name];
+// this[name] = defaultCompleteMethod;
+ }
+
+ private function defaultCompleteMethod():void {
+ trace("default complete method called");
+ }
/**
* Sets up the fixture, for example, instantiate a mock object.
* This method is called before each test is executed.
Modified: trunk/framework/as3/asunit/framework/TestResult.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestResult.as 2006-09-19 16:57:15 UTC (rev 97)
+++ trunk/framework/as3/asunit/framework/TestResult.as 2006-09-19 20:35:05 UTC (rev 98)
@@ -103,18 +103,7 @@
*/
public function run(test:TestCase):void {
startTest(test);
- try {
- test.runBare();
- }
- catch(e:AssertionFailedError) {
- addFailure(test, e);
- }
- catch(ioe:IllegalOperationError) {
- addError(test, ioe);
- }
- finally {
- endTest(test);
- }
+ test.runBare();
}
/**
* Gets the number of run tests.
Modified: trunk/framework/as3/asunit/textui/TestRunnerTest.as
===================================================================
--- trunk/framework/as3/asunit/textui/TestRunnerTest.as 2006-09-19 16:57:15 UTC (rev 97)
+++ trunk/framework/as3/asunit/textui/TestRunnerTest.as 2006-09-19 20:35:05 UTC (rev 98)
@@ -1,5 +1,6 @@
package asunit.textui {
- import asunit.framework.TestCase;
+ import asunit.framework.TestCase;
+ import flash.utils.setTimeout;
public class TestRunnerTest extends TestCase {
private var instance:TestRunner;
@@ -21,9 +22,18 @@
public function testInstantiated():void {
assertTrue("TestRunner instantiated", instance is TestRunner);
}
+
+// public function testAsync():void {
+// setTimeout(testAsyncComplete, 10);
+// }
- public function testStart():void {
- instance.start(TestRunnerTestCaseMock);
+// public function testAsyncComplete():void {
+// fail("test async complete failed");
+// runBare();
+// }
+
+ public function testSomethingComplete():void {
+ trace("testSomethignCOmplete executed");
}
}
}
Modified: trunk/framework/as3/asunit/textui/TestRunnerTestCaseMock.as
===================================================================
--- trunk/framework/as3/asunit/textui/TestRunnerTestCaseMock.as 2006-09-19 16:57:15 UTC (rev 97)
+++ trunk/framework/as3/asunit/textui/TestRunnerTestCaseMock.as 2006-09-19 20:35:05 UTC (rev 98)
@@ -15,6 +15,10 @@
testMethod1Run = true;
}
+ public function testMethod1Completed():void {
+ trace("testMethod1Handler called");
+ }
+
public function testMethod2():void {
testMethod2Run = true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|