|
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.
|