annotate bindings/as3/ext/asunit/framework/TestResult.as @ 770:c54bc2ffbf92 tip

update tags
author convert-repo
date Fri, 16 Dec 2011 11:34:01 +0000
parents 3a0b9700b3d2
children
rev   line source
mas01mj@732 1 package asunit.framework {
mas01mj@732 2 import asunit.errors.AssertionFailedError;
mas01mj@732 3 import asunit.errors.InstanceNotFoundError;
mas01mj@732 4
mas01mj@732 5 /**
mas01mj@732 6 * A <code>TestResult</code> collects the results of executing
mas01mj@732 7 * a test case. It is an instance of the Collecting Parameter pattern.
mas01mj@732 8 * The test framework distinguishes between <i>failures</i> and <i>errors</i>.
mas01mj@732 9 * A failure is anticipated and checked for with assertions. Errors are
mas01mj@732 10 * unanticipated problems like an <code>ArrayIndexOutOfBoundsException</code>.
mas01mj@732 11 *
mas01mj@732 12 * @see Test
mas01mj@732 13 */
mas01mj@732 14 public class TestResult implements TestListener {
mas01mj@732 15 protected var fFailures:Array;
mas01mj@732 16 protected var fErrors:Array;
mas01mj@732 17 protected var fListeners:Array;
mas01mj@732 18 protected var fRunTests:int;
mas01mj@732 19 private var fStop:Boolean;
mas01mj@732 20
mas01mj@732 21 public function TestResult() {
mas01mj@732 22 fFailures = new Array();
mas01mj@732 23 fErrors = new Array();
mas01mj@732 24 fListeners = new Array();
mas01mj@732 25 fRunTests = 0;
mas01mj@732 26 fStop = false;
mas01mj@732 27 }
mas01mj@732 28 /**
mas01mj@732 29 * Adds an error to the list of errors. The passed in exception
mas01mj@732 30 * caused the error.
mas01mj@732 31 */
mas01mj@732 32 public function addError(test:Test, t:Error):void {
mas01mj@732 33 fErrors.push(new TestFailure(test, t));
mas01mj@732 34 var len:uint = fListeners.length;
mas01mj@732 35 var item:TestListener;
mas01mj@732 36 for(var i:uint; i < len; i++) {
mas01mj@732 37 item = TestListener(fListeners[i]);
mas01mj@732 38 item.addError(test, t);
mas01mj@732 39 }
mas01mj@732 40 }
mas01mj@732 41 /**
mas01mj@732 42 * Adds a failure to the list of failures. The passed in exception
mas01mj@732 43 * caused the failure.
mas01mj@732 44 */
mas01mj@732 45 public function addFailure(test:Test, t:AssertionFailedError):void {
mas01mj@732 46 fFailures.push(new TestFailure(test, t));
mas01mj@732 47 var len:uint = fListeners.length;
mas01mj@732 48 var item:TestListener;
mas01mj@732 49 for(var i:uint; i < len; i++) {
mas01mj@732 50 item = TestListener(fListeners[i]);
mas01mj@732 51 item.addFailure(test, t);
mas01mj@732 52 }
mas01mj@732 53 }
mas01mj@732 54 /**
mas01mj@732 55 * Registers a TestListener
mas01mj@732 56 */
mas01mj@732 57 public function addListener(listener:TestListener):void {
mas01mj@732 58 fListeners.push(listener);
mas01mj@732 59 }
mas01mj@732 60 /**
mas01mj@732 61 * Unregisters a TestListener
mas01mj@732 62 */
mas01mj@732 63 public function removeListener(listener:TestListener):void {
mas01mj@732 64 var len:uint = fListeners.length;
mas01mj@732 65 for(var i:uint; i < len; i++) {
mas01mj@732 66 if(fListeners[i] == listener) {
mas01mj@732 67 fListeners.splice(i, 1);
mas01mj@732 68 return;
mas01mj@732 69 }
mas01mj@732 70 }
mas01mj@732 71 throw new InstanceNotFoundError("removeListener called without listener in list");
mas01mj@732 72 }
mas01mj@732 73 /**
mas01mj@732 74 * Gets the number of detected errors.
mas01mj@732 75 */
mas01mj@732 76 public function errorCount():int {
mas01mj@732 77 return fErrors.length;
mas01mj@732 78 }
mas01mj@732 79 /**
mas01mj@732 80 * Returns an Enumeration for the errors
mas01mj@732 81 */
mas01mj@732 82 public function errors():Array {
mas01mj@732 83 return fErrors;
mas01mj@732 84 }
mas01mj@732 85 /**
mas01mj@732 86 * Gets the number of detected failures.
mas01mj@732 87 */
mas01mj@732 88 public function failureCount():int {
mas01mj@732 89 return fFailures.length;
mas01mj@732 90 }
mas01mj@732 91 /**
mas01mj@732 92 * Returns an Enumeration for the failures
mas01mj@732 93 */
mas01mj@732 94 public function failures():Array {
mas01mj@732 95 return fFailures;
mas01mj@732 96 }
mas01mj@732 97
mas01mj@732 98 /**
mas01mj@732 99 * Runs a TestCase.
mas01mj@732 100 */
mas01mj@732 101 public function run(test:Test):void {
mas01mj@732 102 startTest(test);
mas01mj@732 103 test.runBare();
mas01mj@732 104 }
mas01mj@732 105 /**
mas01mj@732 106 * Gets the number of run tests.
mas01mj@732 107 */
mas01mj@732 108 public function runCount():int {
mas01mj@732 109 return fRunTests;
mas01mj@732 110 }
mas01mj@732 111 /**
mas01mj@732 112 * Checks whether the test run should stop
mas01mj@732 113 */
mas01mj@732 114 public function shouldStop():Boolean {
mas01mj@732 115 return fStop;
mas01mj@732 116 }
mas01mj@732 117 /**
mas01mj@732 118 * Informs the result that a test will be started.
mas01mj@732 119 */
mas01mj@732 120 public function startTest(test:Test):void {
mas01mj@732 121 var count:int = test.countTestCases();
mas01mj@732 122 fRunTests += count;
mas01mj@732 123
mas01mj@732 124 var len:uint = fListeners.length;
mas01mj@732 125 var item:TestListener;
mas01mj@732 126 for(var i:uint; i < len; i++) {
mas01mj@732 127 item = TestListener(fListeners[i]);
mas01mj@732 128 item.startTest(test);
mas01mj@732 129 }
mas01mj@732 130 }
mas01mj@732 131
mas01mj@732 132 public function startTestMethod(test:Test, method:String):void {
mas01mj@732 133 var len:uint = fListeners.length;
mas01mj@732 134 var item:TestListener;
mas01mj@732 135 for(var i:uint; i < len; i++) {
mas01mj@732 136 item = TestListener(fListeners[i]);
mas01mj@732 137 item.startTestMethod(test, method);
mas01mj@732 138 }
mas01mj@732 139 }
mas01mj@732 140
mas01mj@732 141 public function endTestMethod(test:Test, method:String):void {
mas01mj@732 142 var len:uint = fListeners.length;
mas01mj@732 143 var item:TestListener;
mas01mj@732 144 for(var i:uint; i < len; i++) {
mas01mj@732 145 item = TestListener(fListeners[i]);
mas01mj@732 146 item.endTestMethod(test, method);
mas01mj@732 147 }
mas01mj@732 148 }
mas01mj@732 149
mas01mj@732 150 /**
mas01mj@732 151 * Informs the result that a test was completed.
mas01mj@732 152 */
mas01mj@732 153 public function endTest(test:Test):void {
mas01mj@732 154 var len:uint = fListeners.length;
mas01mj@732 155 var item:TestListener;
mas01mj@732 156 for(var i:uint; i < len; i++) {
mas01mj@732 157 item = TestListener(fListeners[i]);
mas01mj@732 158 item.endTest(test);
mas01mj@732 159 }
mas01mj@732 160 }
mas01mj@732 161 /**
mas01mj@732 162 * Marks that the test run should stop.
mas01mj@732 163 */
mas01mj@732 164 public function stop():void {
mas01mj@732 165 fStop = true;
mas01mj@732 166 }
mas01mj@732 167 /**
mas01mj@732 168 * Returns whether the entire test was successful or not.
mas01mj@732 169 */
mas01mj@732 170 public function wasSuccessful():Boolean {
mas01mj@732 171 return failureCount() == 0 && errorCount() == 0;
mas01mj@732 172 }
mas01mj@732 173 }
mas01mj@732 174 }