|
From: <luk...@us...> - 2006-09-19 22:23:05
|
Revision: 101
http://svn.sourceforge.net/asunit/?rev=101&view=rev
Author: lukebayes
Date: 2006-09-19 15:22:59 -0700 (Tue, 19 Sep 2006)
Log Message:
-----------
working toward async test methods, seems like it might be working.
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/TestCase.as
trunk/framework/as3/asunit/textui/TestRunnerTest.as
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2006-09-19 22:11:36 UTC (rev 100)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2006-09-19 22:22:59 UTC (rev 101)
@@ -9,6 +9,7 @@
import asunit.util.ArrayIterator;
import flash.net.getClassByAlias;
import flash.utils.setTimeout;
+ import flash.utils.clearTimeout;
/**
* A test case defines the fixture to run multiple tests. To define a test case<br>
@@ -78,11 +79,13 @@
/**
* the name of the test case
*/
+ protected var DEFAULT_TIMEOUT:int = 500;
protected var fName:String;
protected var result:TestResult;
protected var testMethods:Array;
protected var isComplete:Boolean;
protected var context:DisplayObjectContainer;
+ private var asyncMethodTimeoutId:Number;
private var currentMethod:String;
private var runSingle:Boolean;
private var methodIterator:Iterator;
@@ -172,9 +175,7 @@
try {
while(itr.hasNext()) {
name = String(itr.next());
- trace("name: " + name);
if(!runMethod(name)) {
- trace("BLOCKING EXECUTION ON : " + name);
break;
}
}
@@ -182,8 +183,6 @@
finally {
if(!runSingle) {
if(!itr.hasNext() && !methodIsAsynchronous) {
- trace("--------------");
- trace("INSIDE THE END");
cleanUp();
result.endTest(this);
isComplete = true;
@@ -207,6 +206,10 @@
private function runMethod(methodName:String):Boolean {
try {
+ if(!isNaN(asyncMethodTimeoutId)) {
+ clearTimeout(asyncMethodTimeoutId);
+ asyncMethodTimeoutId = NaN;
+ }
setUp();
currentMethod = methodName;
try {
@@ -277,6 +280,7 @@
protected function addAsync(handler:Function):Function {
methodIsAsynchronous = true;
var context:Object = this;
+ asyncMethodTimeoutId = setTimeout(timeoutHandler, DEFAULT_TIMEOUT);
return function(args:*):* {
try {
handler.apply(context, arguments);
@@ -292,6 +296,12 @@
}
}
+ protected function timeoutHandler():void {
+ result.addError(this, new IllegalOperationError("TestCase.DEFAULT_TIMEOUT (" + DEFAULT_TIMEOUT + "ms) exceeded on an asynchronous test method."));
+ methodIsAsynchronous = false;
+ runBare();
+ }
+
protected function addChild(child:DisplayObject):DisplayObject {
return getContext().addChild(child);
}
Modified: trunk/framework/as3/asunit/textui/TestRunnerTest.as
===================================================================
--- trunk/framework/as3/asunit/textui/TestRunnerTest.as 2006-09-19 22:11:36 UTC (rev 100)
+++ trunk/framework/as3/asunit/textui/TestRunnerTest.as 2006-09-19 22:22:59 UTC (rev 101)
@@ -27,14 +27,22 @@
public function testAsync():void {
var handler:Function = addAsync(asyncCompleteHandler);
- setTimeout(handler, 1000, new Event(Event.ACTIVATE));
+ setTimeout(handler, 400, new Event(Event.ACTIVATE));
}
public function asyncCompleteHandler(event:Event):void {
-// throw new IllegalOperationError("what the fuck?");
- fail("test async complete failed");
+// throw new IllegalOperationError("what the heck?");
}
+ public function testAsync2():void {
+ var handler:Function = addAsync(async2CompleteHandler);
+ setTimeout(handler, 40);
+ }
+
+ public function async2CompleteHandler():void {
+// fail("test async complete failed");
+ }
+
public function testSomethingComplete():void {
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2007-11-09 08:43:46
|
Revision: 175
http://asunit.svn.sourceforge.net/asunit/?rev=175&view=rev
Author: lukebayes
Date: 2007-11-09 00:43:51 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
Added xml trace output for Cruise control test results
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/Test.as
trunk/framework/as3/asunit/framework/TestCase.as
trunk/framework/as3/asunit/framework/TestFailure.as
trunk/framework/as3/asunit/textui/XMLResultPrinter.as
Modified: trunk/framework/as3/asunit/framework/Test.as
===================================================================
--- trunk/framework/as3/asunit/framework/Test.as 2007-11-09 00:32:12 UTC (rev 174)
+++ trunk/framework/as3/asunit/framework/Test.as 2007-11-09 08:43:51 UTC (rev 175)
@@ -4,6 +4,7 @@
public interface Test extends IEventDispatcher {
function countTestCases():int;
+ function getName():String;
function toString():String;
function setResult(result:TestResult):void;
function run():void;
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2007-11-09 00:32:12 UTC (rev 174)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2007-11-09 08:43:51 UTC (rev 175)
@@ -277,7 +277,12 @@
* Returns a string representation of the test case
*/
override public function toString():String {
- return getName() + "." + getCurrentMethod() + "()";
+ if(getCurrentMethod()) {
+ return getName() + "." + getCurrentMethod() + "()";
+ }
+ else {
+ return getName();
+ }
}
/**
* Gets the name of a TestCase
Modified: trunk/framework/as3/asunit/framework/TestFailure.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestFailure.as 2007-11-09 00:32:12 UTC (rev 174)
+++ trunk/framework/as3/asunit/framework/TestFailure.as 2007-11-09 08:43:51 UTC (rev 175)
@@ -8,6 +8,7 @@
*/
public class TestFailure {
protected var fFailedTest:String;
+ protected var fFailedTestName:String;
protected var fThrownException:Error;
/**
@@ -15,15 +16,23 @@
*/
public function TestFailure(failedTest:Test, thrownException:Error) {
fFailedTest = failedTest.toString();
+ fFailedTestName = failedTest.getName();
fThrownException = thrownException;
}
/**
- * Gets the failed test.
+ * Gets the failed test class with method name.
*/
public function failedTest():String {
return fFailedTest;
}
+
/**
+ * Gets the failed test class name.
+ */
+ public function failedTestName():String {
+ return fFailedTestName;
+ }
+ /**
* Gets the thrown exception.
*/
public function thrownException():Error {
Modified: trunk/framework/as3/asunit/textui/XMLResultPrinter.as
===================================================================
--- trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2007-11-09 00:32:12 UTC (rev 174)
+++ trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2007-11-09 08:43:51 UTC (rev 175)
@@ -2,29 +2,97 @@
import asunit.framework.TestResult;
import asunit.framework.TestFailure;
+ import asunit.framework.Test;
+ import flash.utils.Dictionary;
- public class XMLResultPrinter extends ResultPrinter {
+ public class XMLResultPrinter extends ResultPrinter {
+
+ protected var results:Dictionary;
+ protected var currentResult:XMLTestResult;
+
+ public function XMLResultPrinter() {
+ results = new Dictionary();
+ }
+
+ override public function startTest(test:Test):void {
+ super.startTest(test);
+ results[test.getName()] = new XMLTestResult(test);
+ }
+/*
+<testsuites>
+ <testsuite name="Flash Profile Card AsUnit Test Suite" errors="1" failures="1" tests="8" time="8.002">
+ <testcase classname="lib.test.cases.FailureTest" name="testError">
+ <failure type="Error">Reference runtime test error</failure>
+ </testcase>
+ <testcase classname="lib.test.cases.FailureTest" name="testAssertion">
+ <failure type="AssertionFailedError">Reference assertion test failure</failure>
+ </testcase>
+ </testsuite>
+</testsuites>
+*/
override public function printResult(result:TestResult, runTime:Number):void {
super.printResult(result, runTime);
- trace("<XMLResultPrinter>");
- trace("PRINT RESULT CALLED with: ");
- trace("runCount: " + result.runCount());
- trace("errorCount: " + result.errorCount());
- trace("failureCount: " + result.failureCount());
+
if(result.errorCount()) {
var error:TestFailure;
for each(error in result.errors()) {
- trace("error: " + error.toString());
+ results[error.failedTestName()].addFailure(error);
}
}
if(result.failureCount()) {
var failure:TestFailure;
for each(failure in result.failures()) {
- trace("failure: " + failure.thrownException().getStackTrace());
+ results[failure.failedTestName()].addFailure(failure);
}
}
+ trace("<XMLResultPrinter>");
+ trace("<?xml version='1.0' encoding='UTF-8'?>");
+ trace("<testsuites>");
+ trace("<testsuite name='AsUnit Test Suite' errors='" + result.errorCount() + "' failures='" + result.failureCount() + "' tests='" + result.runCount() + "' time='" + elapsedTimeAsString(runTime) + " seconds'>");
+ var xmlTestResult:XMLTestResult;
+ for each(xmlTestResult in results) {
+ trace(xmlTestResult.toString());
+ }
+ trace("</testsuite>");
+ trace("</testsuites>");
trace("</XMLResultPrinter>");
- }
+ }
}
-}
+}
+
+import asunit.framework.Test;
+import asunit.framework.TestFailure;
+
+class XMLTestResult {
+
+ private var test:Test;
+ private var failures:Array;
+ private var errors:Array;
+
+ public function XMLTestResult(test:Test) {
+ this.test = test;
+ failures = new Array();
+ }
+
+ public function addFailure(failure:TestFailure):void {
+ failures.push(failure);
+ }
+
+ private function renderFailures():String {
+ var result:String = "";
+ var failure:TestFailure;
+ for each(failure in failures) {
+ result += "<failure type='" + failure.thrownException().name + "'>" + failure.thrownException().getStackTrace() + "\n</failure>\n";
+ }
+ return result;
+ }
+
+ public function toString():String {
+ var str:String = "";
+ str += "<testcase classname='" + test.getName() + "'>\n";
+ str += renderFailures();
+ str += "</testcase>";
+ return str;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2007-11-09 17:55:54
|
Revision: 176
http://asunit.svn.sourceforge.net/asunit/?rev=176&view=rev
Author: lukebayes
Date: 2007-11-09 09:55:54 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
Working on Continuous Integration support
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/Test.as
trunk/framework/as3/asunit/framework/TestCase.as
trunk/framework/as3/asunit/framework/TestFailure.as
trunk/framework/as3/asunit/textui/ResultPrinter.as
trunk/framework/as3/asunit/textui/XMLResultPrinter.as
Modified: trunk/framework/as3/asunit/framework/Test.as
===================================================================
--- trunk/framework/as3/asunit/framework/Test.as 2007-11-09 08:43:51 UTC (rev 175)
+++ trunk/framework/as3/asunit/framework/Test.as 2007-11-09 17:55:54 UTC (rev 176)
@@ -5,6 +5,7 @@
public interface Test extends IEventDispatcher {
function countTestCases():int;
function getName():String;
+ function getTestMethods():Array;
function toString():String;
function setResult(result:TestResult):void;
function run():void;
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2007-11-09 08:43:51 UTC (rev 175)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2007-11-09 17:55:54 UTC (rev 176)
@@ -154,6 +154,10 @@
testMethods.push(name);
}
}
+
+ public function getTestMethods():Array {
+ return testMethods;
+ }
/**
* Counts the number of test cases executed by run(TestResult result).
Modified: trunk/framework/as3/asunit/framework/TestFailure.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestFailure.as 2007-11-09 08:43:51 UTC (rev 175)
+++ trunk/framework/as3/asunit/framework/TestFailure.as 2007-11-09 17:55:54 UTC (rev 176)
@@ -7,32 +7,29 @@
* @see TestResult
*/
public class TestFailure {
- protected var fFailedTest:String;
- protected var fFailedTestName:String;
+ protected var fFailedTest:Test;
+ protected var fFailedTestMethod:String;
protected var fThrownException:Error;
/**
* Constructs a TestFailure with the given test and exception.
*/
public function TestFailure(failedTest:Test, thrownException:Error) {
- fFailedTest = failedTest.toString();
- fFailedTestName = failedTest.getName();
+ fFailedTest = failedTest;
+ fFailedTestMethod = failedTest.getCurrentMethod();
fThrownException = thrownException;
}
+
+ public function failedFeature():String {
+ return failedTest().getName() + '.' + fFailedTestMethod + "()";
+ }
/**
- * Gets the failed test class with method name.
+ * Gets the failed test case.
*/
- public function failedTest():String {
+ public function failedTest():Test {
return fFailedTest;
}
-
/**
- * Gets the failed test class name.
- */
- public function failedTestName():String {
- return fFailedTestName;
- }
- /**
* Gets the thrown exception.
*/
public function thrownException():Error {
Modified: trunk/framework/as3/asunit/textui/ResultPrinter.as
===================================================================
--- trunk/framework/as3/asunit/textui/ResultPrinter.as 2007-11-09 08:43:51 UTC (rev 175)
+++ trunk/framework/as3/asunit/textui/ResultPrinter.as 2007-11-09 17:55:54 UTC (rev 176)
@@ -133,7 +133,7 @@
// I feel like making this a println, then adding a line giving the throwable a chance to print something
// before we get to the stack trace.
var startIndex:uint = textArea.text.length;
- println(count + ") " + booBoo.failedTest());
+ println(count + ") " + booBoo.failedFeature());
var endIndex:uint = textArea.text.length;
var format:TextFormat = textArea.getTextFormat();
Modified: trunk/framework/as3/asunit/textui/XMLResultPrinter.as
===================================================================
--- trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2007-11-09 08:43:51 UTC (rev 175)
+++ trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2007-11-09 17:55:54 UTC (rev 176)
@@ -37,13 +37,13 @@
if(result.errorCount()) {
var error:TestFailure;
for each(error in result.errors()) {
- results[error.failedTestName()].addFailure(error);
+ results[error.failedTest().getName()].addFailure(error);
}
}
if(result.failureCount()) {
var failure:TestFailure;
for each(failure in result.failures()) {
- results[failure.failedTestName()].addFailure(failure);
+ results[failure.failedTest().getName()].addFailure(failure);
}
}
trace("<XMLResultPrinter>");
@@ -90,7 +90,7 @@
public function toString():String {
var str:String = "";
- str += "<testcase classname='" + test.getName() + "'>\n";
+ str += "<testcase classname='" + test.getName() + "' name='[method name here]'>\n";
str += renderFailures();
str += "</testcase>";
return str;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2007-11-09 18:09:21
|
Revision: 177
http://asunit.svn.sourceforge.net/asunit/?rev=177&view=rev
Author: lukebayes
Date: 2007-11-09 10:09:26 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
Improving Continuous Integration Printer
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/TestFailure.as
trunk/framework/as3/asunit/textui/XMLResultPrinter.as
Modified: trunk/framework/as3/asunit/framework/TestFailure.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestFailure.as 2007-11-09 17:55:54 UTC (rev 176)
+++ trunk/framework/as3/asunit/framework/TestFailure.as 2007-11-09 18:09:26 UTC (rev 177)
@@ -21,8 +21,13 @@
}
public function failedFeature():String {
- return failedTest().getName() + '.' + fFailedTestMethod + "()";
+ return failedTest().getName() + '.' + fFailedTestMethod;
}
+
+ public function failedMethod():String {
+ return fFailedTestMethod;
+ }
+
/**
* Gets the failed test case.
*/
Modified: trunk/framework/as3/asunit/textui/XMLResultPrinter.as
===================================================================
--- trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2007-11-09 17:55:54 UTC (rev 176)
+++ trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2007-11-09 18:09:26 UTC (rev 177)
@@ -71,7 +71,7 @@
private var errors:Array;
public function XMLTestResult(test:Test) {
- this.test = test;
+ this.test = test;
failures = new Array();
}
@@ -88,11 +88,33 @@
return result;
}
+ private function renderOpener(methodName:String):String {
+ return "<testcase classname='" + test.getName() + "' name='" + methodName + "'>\n";
+ }
+
+ private function renderFailure(methodName:String):String {
+ var failure:TestFailure;
+ for each(failure in failures) {
+ if(failure.failedMethod() == methodName) {
+ return "<failure type='" + failure.thrownException().name + "'>" + failure.thrownException().getStackTrace() + "\n</failure>\n";
+ }
+ }
+ return '';
+ }
+
+ private function renderCloser():String {
+ return '</testcase>\n';
+ }
+
public function toString():String {
- var str:String = "";
- str += "<testcase classname='" + test.getName() + "' name='[method name here]'>\n";
- str += renderFailures();
- str += "</testcase>";
+ var str:String = '';
+ var method:String;
+ var failure:TestFailure;
+ for each(method in test.getTestMethods()) {
+ str += renderOpener(method);
+ str += renderFailure(method);
+ str += renderCloser();
+ }
return str;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2008-02-20 00:41:01
|
Revision: 184
http://asunit.svn.sourceforge.net/asunit/?rev=184&view=rev
Author: lukebayes
Date: 2008-02-19 16:40:51 -0800 (Tue, 19 Feb 2008)
Log Message:
-----------
Integrated Cruise Control JUnit XML Reporting
Updated TestListener interface and methods that TestCase calls
Updated XMLResultPrinter for more accurate result set
Modified Paths:
--------------
trunk/framework/as3/asunit/framework/Test.as
trunk/framework/as3/asunit/framework/TestCase.as
trunk/framework/as3/asunit/framework/TestListener.as
trunk/framework/as3/asunit/framework/TestResult.as
trunk/framework/as3/asunit/framework/TestSuite.as
trunk/framework/as3/asunit/textui/ResultPrinter.as
trunk/framework/as3/asunit/textui/TestRunner.as
trunk/framework/as3/asunit/textui/XMLResultPrinter.as
Added Paths:
-----------
trunk/framework/as3/asunit/framework/TestMethod.as
Modified: trunk/framework/as3/asunit/framework/Test.as
===================================================================
--- trunk/framework/as3/asunit/framework/Test.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/framework/Test.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -7,8 +7,9 @@
function getName():String;
function getTestMethods():Array;
function toString():String;
- function setResult(result:TestResult):void;
+ function setResult(result:TestListener):void;
function run():void;
+ function runBare():void;
function getCurrentMethod():String;
function getIsComplete():Boolean;
function setContext(context:DisplayObjectContainer):void;
Modified: trunk/framework/as3/asunit/framework/TestCase.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestCase.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/framework/TestCase.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -1,19 +1,17 @@
package asunit.framework {
import asunit.errors.AssertionFailedError;
+ import asunit.util.ArrayIterator;
+ import asunit.util.Iterator;
import flash.display.DisplayObject;
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.events.Event;
+ import flash.events.TimerEvent;
import flash.utils.Timer;
- import flash.events.TimerEvent;
+ import flash.utils.describeType;
+ import flash.utils.getDefinitionByName;
import flash.utils.setTimeout;
- import flash.utils.clearTimeout;
- import flash.utils.getDefinitionByName;
/**
* A test case defines the fixture to run multiple tests. To define a test case<br>
@@ -86,7 +84,7 @@
protected static const TEAR_DOWN:int = 3;
protected static const DEFAULT_TIMEOUT:int = 1000;
protected var fName:String;
- protected var result:TestResult;
+ protected var result:TestListener;
protected var testMethods:Array;
protected var isComplete:Boolean;
protected var context:DisplayObjectContainer;
@@ -189,11 +187,11 @@
getResult().run(this);
}
- public function setResult(result:TestResult):void {
+ public function setResult(result:TestListener):void {
this.result = result;
}
- protected function getResult():TestResult {
+ protected function getResult():TestListener {
return (result == null) ? createResult() : result;
}
@@ -239,6 +237,7 @@
methodIsAsynchronous = false;
if(currentState == PRE_SET_UP) {
currentState = SET_UP;
+ getResult().startTestMethod(this, methodName);
setUp(); // setUp may be async and change the state of methodIsAsynchronous
}
currentMethod = methodName;
@@ -362,6 +361,7 @@
return;
}
if(!runSingle) {
+ getResult().endTestMethod(this, currentMethod);
tearDown();
layoutManager.resetAll();
}
Modified: trunk/framework/as3/asunit/framework/TestListener.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestListener.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/framework/TestListener.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -2,21 +2,34 @@
import asunit.errors.AssertionFailedError;
public interface TestListener {
+
/**
- * An error occurred.
- */
- function addError(test:Test, t:Error):void;
+ * Run the provided Test.
+ */
+ function run(test:Test):void;
/**
+ * A test started.
+ */
+ function startTest(test:Test):void;
+ /**
* A failure occurred.
*/
function addFailure(test:Test, t:AssertionFailedError):void;
/**
+ * An error occurred.
+ */
+ function addError(test:Test, t:Error):void;
+ /**
+ * A test method has begun execution.
+ */
+ function startTestMethod(test:Test, methodName:String):void;
+ /**
+ * A test method has completed.
+ */
+ function endTestMethod(test:Test, methodName:String):void;
+ /**
* A test ended.
*/
function endTest(test:Test):void;
- /**
- * A test started.
- */
- function startTest(test:Test):void;
}
}
\ No newline at end of file
Added: trunk/framework/as3/asunit/framework/TestMethod.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestMethod.as (rev 0)
+++ trunk/framework/as3/asunit/framework/TestMethod.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -0,0 +1,38 @@
+package asunit.framework {
+
+ import flash.utils.getTimer;
+
+ /**
+ * A <code>TestFailure</code> collects a failed test together with
+ * the caught exception.
+ * @see TestResult
+ */
+ public class TestMethod {
+ protected var test:Test;
+ protected var method:String;
+
+ private var _duration:Number;
+ private var start:Number;
+
+ /**
+ * Constructs a TestMethod with a given Test and method name.
+ */
+ public function TestMethod(test:Test, method:String) {
+ this.test = test;
+ this.method = method;
+ start = getTimer();
+ }
+
+ public function getName():String {
+ return method;
+ }
+
+ public function endTest(test:Test):void {
+ _duration = (getTimer() - start) * .001;
+ }
+
+ public function duration():Number {
+ return _duration;
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/framework/as3/asunit/framework/TestMethod.as
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/framework/as3/asunit/framework/TestResult.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestResult.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/framework/TestResult.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -2,9 +2,6 @@
import asunit.errors.AssertionFailedError;
import asunit.errors.InstanceNotFoundError;
- import flash.errors.IllegalOperationError;
- import flash.events.EventDispatcher;
-
/**
* A <code>TestResult</code> collects the results of executing
* a test case. It is an instance of the Collecting Parameter pattern.
@@ -14,7 +11,7 @@
*
* @see Test
*/
- public class TestResult {
+ public class TestResult implements TestListener {
protected var fFailures:Array;
protected var fErrors:Array;
protected var fListeners:Array;
@@ -101,7 +98,7 @@
/**
* Runs a TestCase.
*/
- public function run(test:TestCase):void {
+ public function run(test:Test):void {
startTest(test);
test.runBare();
}
@@ -131,6 +128,25 @@
item.startTest(test);
}
}
+
+ public function startTestMethod(test:Test, method:String):void {
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.startTestMethod(test, method);
+ }
+ }
+
+ public function endTestMethod(test:Test, method:String):void {
+ var len:uint = fListeners.length;
+ var item:TestListener;
+ for(var i:uint; i < len; i++) {
+ item = TestListener(fListeners[i]);
+ item.endTestMethod(test, method);
+ }
+ }
+
/**
* Informs the result that a test was completed.
*/
Modified: trunk/framework/as3/asunit/framework/TestSuite.as
===================================================================
--- trunk/framework/as3/asunit/framework/TestSuite.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/framework/TestSuite.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -1,8 +1,9 @@
package asunit.framework {
+ import asunit.util.ArrayIterator;
+ import asunit.util.Iterator;
+
import flash.display.DisplayObjectContainer;
import flash.events.Event;
- import asunit.util.Iterator;
- import asunit.util.ArrayIterator;
/**
* A <code>TestSuite</code> is a <code>Composite</code> of Tests.
@@ -53,7 +54,7 @@
* Runs the tests and collects their result in a TestResult.
*/
public override function run():void {
- var result:TestResult = getResult();
+ var result:TestListener = getResult();
var test:Test;
var itr:Iterator = getIterator();
while(itr.hasNext()) {
Modified: trunk/framework/as3/asunit/textui/ResultPrinter.as
===================================================================
--- trunk/framework/as3/asunit/textui/ResultPrinter.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/textui/ResultPrinter.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -6,16 +6,11 @@
import asunit.framework.TestResult;
import asunit.runner.BaseTestRunner;
import asunit.runner.Version;
-
- import flash.display.Shape;
+
import flash.display.Sprite;
- import flash.display.Stage;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
import flash.events.*;
import flash.text.TextField;
import flash.text.TextFormat;
- import flash.ui.Keyboard;
import flash.utils.setTimeout;
public class ResultPrinter extends Sprite implements TestListener {
@@ -76,9 +71,14 @@
public function print(...args:Array):void {
textArea.appendText(args.toString());
}
- /* API for use by textui.TestRunner
+
+ /**
+ * API for use by textui.TestRunner
*/
-
+
+ public function run(test:Test):void {
+ }
+
public function printResult(result:TestResult, runTime:Number):void {
printHeader(runTime);
printErrors(result);
@@ -174,27 +174,39 @@
}
/**
- * @see junit.framework.TestListener#addError(Test, Throwable)
+ * @see asunit.framework.TestListener#addError(Test, Throwable)
*/
public function addError(test:Test, t:Error):void {
print("E");
}
/**
- * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
+ * @see asunit.framework.TestListener#addFailure(Test, AssertionFailedError)
*/
public function addFailure(test:Test, t:AssertionFailedError):void {
print("F");
}
/**
- * @see junit.framework.TestListener#endTest(Test)
+ * @see asunit.framework.TestListener#endTestMethod(test, testMethod);
*/
+ public function startTestMethod(test:Test, methodName:String):void {
+ }
+
+ /**
+ * @see asunit.framework.TestListener#endTestMethod(test, testMethod);
+ */
+ public function endTestMethod(test:Test, methodName:String):void {
+ }
+
+ /**
+ * @see asunit.framework.TestListener#endTest(Test)
+ */
public function endTest(test:Test):void {
}
/**
- * @see junit.framework.TestListener#startTest(Test)
+ * @see asunit.framework.TestListener#startTest(Test)
*/
public function startTest(test:Test):void {
var count:uint = test.countTestCases();
Modified: trunk/framework/as3/asunit/textui/TestRunner.as
===================================================================
--- trunk/framework/as3/asunit/textui/TestRunner.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/textui/TestRunner.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -69,7 +69,6 @@
*/
public function start(testCase:Class, testMethod:String = null, showTrace:Boolean = false):TestResult {
// fscommand("showmenu", "false");
-
try {
var instance:Test;
if(testMethod != null) {
Modified: trunk/framework/as3/asunit/textui/XMLResultPrinter.as
===================================================================
--- trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2008-02-19 22:39:21 UTC (rev 183)
+++ trunk/framework/as3/asunit/textui/XMLResultPrinter.as 2008-02-20 00:40:51 UTC (rev 184)
@@ -1,7 +1,9 @@
package asunit.textui {
+ import asunit.errors.AssertionFailedError;
import asunit.framework.Test;
import asunit.framework.TestFailure;
+ import asunit.framework.TestListener;
import asunit.framework.TestResult;
import flash.utils.Dictionary;
@@ -9,7 +11,6 @@
public class XMLResultPrinter extends ResultPrinter {
protected var results:Dictionary;
- protected var currentResult:XMLTestResult;
public function XMLResultPrinter() {
results = new Dictionary();
@@ -17,12 +18,35 @@
override public function startTest(test:Test):void {
super.startTest(test);
- results[test.getName()] = new XMLTestResult(test);
+ var result:TestListener = new XMLTestResult(test);
+ results[test.getName()] = result;
+ result.startTest(test);
}
override public function endTest(test:Test):void {
+ super.endTest(test);
results[test.getName()].endTest(test);
}
+
+ override public function startTestMethod(test:Test, methodName:String):void {
+ super.startTestMethod(test, methodName);
+ results[test.getName()].startTestMethod(test, methodName);
+ }
+
+ override public function endTestMethod(test:Test, methodName:String):void {
+ super.endTestMethod(test, methodName);
+ results[test.getName()].endTestMethod(test, methodName);
+ }
+
+ override public function addFailure(test:Test, t:AssertionFailedError):void {
+ super.addFailure(test, t);
+ results[test.getName()].addFailure(test);
+ }
+
+ override public function addError(test:Test, t:Error):void {
+ super.addError(test, t);
+ results[test.getName()].addError(test);
+ }
/*
<testsuites>
@@ -42,6 +66,7 @@
override public function printResult(result:TestResult, runTime:Number):void {
super.printResult(result, runTime);
+/*
if(result.errorCount()) {
var error:TestFailure;
for each(error in result.errors()) {
@@ -54,10 +79,12 @@
results[failure.failedTest().getName()].addFailure(failure);
}
}
+*/
+
trace("<XMLResultPrinter>");
trace("<?xml version='1.0' encoding='UTF-8'?>");
trace("<testsuites>");
- trace("<testsuite name='AsUnit Test Suite' errors='" + result.errorCount() + "' failures='" + result.failureCount() + "' tests='" + result.runCount() + "' time='" + elapsedTimeAsString(runTime) + "'>");
+ trace("<testsuite name='AllTests' errors='" + result.errorCount() + "' failures='" + result.failureCount() + "' tests='" + result.runCount() + "' time='" + elapsedTimeAsString(runTime) + "'>");
var xmlTestResult:XMLTestResult;
for each(xmlTestResult in results) {
trace(xmlTestResult.toString());
@@ -72,59 +99,128 @@
import asunit.framework.Test;
import asunit.framework.TestFailure;
import flash.utils.getQualifiedClassName;
-import flash.utils.getTimer;
+import flash.utils.getTimer;
+import asunit.framework.TestListener;
+import asunit.errors.AssertionFailedError;
+import asunit.framework.TestMethod;
+import flash.utils.Dictionary;
-class XMLTestResult {
+class XMLTestResult implements TestListener {
+ private var _duration:Number;
+ private var start:Number;
private var test:Test;
private var testName:String;
+ private var failureHash:Dictionary;
private var failures:Array;
+ private var errorHash:Dictionary;
private var errors:Array;
- private var start:Number;
- private var duration:Number;
+ private var methodHash:Dictionary;
+ private var methods:Array;
public function XMLTestResult(test:Test) {
- start = getTimer();
this.test = test;
testName = test.getName().split("::").join(".");
failures = new Array();
+ errors = new Array();
+ methods = new Array();
+
+ failureHash = new Dictionary();
+ errorHash = new Dictionary();
+ methodHash = new Dictionary();
}
+
+ public function startTest(test:Test):void {
+ start = getTimer();
+ }
- public function addFailure(failure:TestFailure):void {
+ public function run(test:Test):void {
+ }
+
+ public function addError(test:Test, t:Error):void {
+ var failure:TestFailure = new TestFailure(test, t);
+ errors.push(failure);
+ errorHash[failure.failedMethod()] = failure;
+ }
+
+ public function addFailure(test:Test, t:AssertionFailedError):void {
+ var failure:TestFailure = new TestFailure(test, t);
failures.push(failure);
+ failureHash[failure.failedMethod()] = failure;
}
-
+
+ public function startTestMethod(test:Test, methodName:String):void {
+ var method:TestMethod = new TestMethod(test, methodName);
+ methods.push(method);
+ methodHash[method.getName()] = method;
+ }
+
+ public function endTestMethod(test:Test, methodName:String):void {
+ methodHash[methodName].endTest(test);
+ }
+
public function endTest(test:Test):void {
- duration = (getTimer() - start) * .001;
+ _duration = (getTimer() - start) * .001;
}
- private function renderOpener(methodName:String):String {
- return "<testcase classname='" + testName + "' name='" + methodName + "' time='" + duration + "'>\n";
+ private function errorCount():int {
+ return errors.length;
}
- private function renderFailure(methodName:String):String {
- var failure:TestFailure;
- for each(failure in failures) {
- if(failure.failedMethod() == methodName) {
- return "<failure type='" + getQualifiedClassName(failure.thrownException()).split("::").join(".") + "'>" + failure.thrownException().getStackTrace() + "\n</failure>\n";
- }
+ private function failureCount():int {
+ return failures.length;
+ }
+
+ private function duration():Number {
+ return _duration;
+ }
+
+ private function renderSuiteOpener():String {
+ return "<testsuite name='" + testName + "' errors='" + errorCount() + "' failures='" + failureCount() + "' tests='" + methods.length + "' time='" + duration() + "'>\n";
+ }
+
+ private function renderTestOpener(methodName:String):String {
+ return "<testcase classname='" + testName + "' name='" + methodName + "' time='" + methodHash[methodName].duration() + "'>\n";
+ }
+
+ private function renderTestBody(method:String):String {
+ if(errorHash[method]) {
+ return renderError(errorHash[method]);
}
- return '';
+ else if(failureHash[method]) {
+ return renderFailure(failureHash[method]);
+ }
+ else {
+ return "";
+ }
}
- private function renderCloser():String {
+ private function renderError(failure:TestFailure):String {
+ return "<error type='" + getQualifiedClassName(failure.thrownException()).split("::").join(".") + "'>" + failure.thrownException().getStackTrace() + "\n</failure>\n";
+ }
+
+ private function renderFailure(failure:TestFailure):String {
+ return "<failure type='" + getQualifiedClassName(failure.thrownException()).split("::").join(".") + "'>" + failure.thrownException().getStackTrace() + "\n</failure>\n";
+ }
+
+ private function renderTestCloser():String {
return '</testcase>\n';
}
+ private function renderSuiteCloser():String {
+ return '</testsuite>\n';
+ }
+
public function toString():String {
var str:String = '';
- var method:String;
var failure:TestFailure;
- for each(method in test.getTestMethods()) {
- str += renderOpener(method);
- str += renderFailure(method);
- str += renderCloser();
+ str += renderSuiteOpener();
+ for(var name:String in methodHash) {
+ str += renderTestOpener(name);
+ str += renderTestBody(name);
+ str += renderTestCloser();
}
+ str += renderSuiteCloser();
return str;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luk...@us...> - 2008-02-25 10:39:44
|
Revision: 188
http://asunit.svn.sourceforge.net/asunit/?rev=188&view=rev
Author: lukebayes
Date: 2008-02-25 02:39:47 -0800 (Mon, 25 Feb 2008)
Log Message:
-----------
Removed unused AbstractMemberCalledError
Modified Paths:
--------------
trunk/framework/as3/asunit/textui/TestRunner.as
Removed Paths:
-------------
trunk/framework/as3/asunit/errors/AbstractMemberCalledError.as
Deleted: trunk/framework/as3/asunit/errors/AbstractMemberCalledError.as
===================================================================
--- trunk/framework/as3/asunit/errors/AbstractMemberCalledError.as 2008-02-20 00:56:07 UTC (rev 187)
+++ trunk/framework/as3/asunit/errors/AbstractMemberCalledError.as 2008-02-25 10:39:47 UTC (rev 188)
@@ -1,10 +0,0 @@
-package asunit.errors {
-
- public class AbstractMemberCalledError extends Error {
-
- public function AbstractMemberCalledError(message:String) {
- super(message);
- name = "AbstractMemberCalledError";
- }
- }
-}
\ No newline at end of file
Modified: trunk/framework/as3/asunit/textui/TestRunner.as
===================================================================
--- trunk/framework/as3/asunit/textui/TestRunner.as 2008-02-20 00:56:07 UTC (rev 187)
+++ trunk/framework/as3/asunit/textui/TestRunner.as 2008-02-25 10:39:47 UTC (rev 188)
@@ -1,5 +1,4 @@
package asunit.textui {
- import asunit.errors.AbstractMemberCalledError;
import asunit.framework.Test;
import asunit.framework.TestResult;
@@ -13,7 +12,7 @@
import flash.utils.getTimer;
import flash.utils.setInterval;
import flash.utils.Timer;
- import flash.events.TimerEvent;
+ import flash.events.TimerEvent;
import flash.display.DisplayObject;
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|