I have not been able to get AS2Unit to report anything useful other than the number of tests. It always reports "OK" no matter how impossible or bogus my test is. It never finds anything wrong or fails.

Case in point are the simple Name class below and its companion tester (NameTester) class. Notice the last method in the tester (testTestFails) is designed to fail.

Drop a AS2Unit instance on the stage, add the following code to the first frame:

import NameTester;
var classes:Array = [NameTester];

and run...

I get:

...
Time: 0.001 seconds

OK (3 tests)

!!!

Now, perhaps I am not doing things right do to the fact that there is NO DOCUMENTATION for AS2Unit that I could find other than the article on FlashMagazine in which the methods to use for assertions are enumerated... without argument signatures!!!

Anyone know how to get this "suite" to work, is it reliable?

Isaac


Class to test:

class Name {
        private var firstName:String;
        private var lastName:String;
        private var middleInitial:String;
        
public function Name(firstName:String, middleInitial:String, lastName:String) {
                this.firstName = firstName;
                this.lastName = lastName;
                if(middleInitial == null) middleInitial = "";
if(middleInitial.length > 1) middleInitial = middleInitial.substring (0, 1); if(middleInitial.length == 1) this.middleInitial = middleInitial + ".";
                else this.middleInitial = "";
        }
        
        public function getFirstName():String {
                return this.firstName;
        }

        public function getLastName():String {
                return this.lastName;
        }
        
        public function getMiddleInitial():String {
                return this.middleInitial;
        }
        
        public function hasMiddleInitial():Boolean {
                return this.middleInitial.length == 2;
        }
        
        public function equals(other:Object):Boolean {
                if(other == null) return false;
                if(!(other instanceof Name)) return false;
                var that:Name = Name(other);
                if(this.getFullName() == that.getFullName()) return true;
                return false;
        }
        
        public function getFullName():String {
return this.firstName + ((this.middleInitial.length == 2) ? (" " + this.middleInitial + " ") : " ");
        }
        
        public function toString():String {
                return getFullName();
        }
}

Tester Class:


import Name;
import as2unit.framework.TestCase

class NameTester extends TestCase {
        
        private static var FIRSTNAME:String = "Isaac";
        private static var MIDDLEINITIAL:String = "";
        private static var LASTNAME:String = "Rivera";
private static var CONTROLNAME:Name = new Name(FIRSTNAME, MIDDLEINITIAL, LASTNAME);
        
        public function NameTester() {}
        
        public function testGettersReturnCorrectValues():Void {
                var testName:Name = new Name(FIRSTNAME, MIDDLEINITIAL, 
LASTNAME);
                
                assertNotNull(testName);
                assertNotNull(CONTROLNAME);
                
                assertNotNull(testName.getFirstName());
                assertNotNull(CONTROLNAME.getFirstName());
                assertNotNull(testName.getMiddleInitial());
                assertNotNull(CONTROLNAME.getMiddleInitial());
                assertNotNull(testName.getLastName());
                assertNotNull(CONTROLNAME.getLastName());
                
                assertEquals(FIRSTNAME, testName.getFirstName());
                assertEquals(MIDDLEINITIAL, testName.getMiddleInitial());
                assertEquals(LASTNAME, testName.getLastName());
                
                assertFalse(testName.hasMiddleInitial());
        }
        
        public function testEqualsWorksCorrectly():Void {
                var testName:Name = new Name(FIRSTNAME, MIDDLEINITIAL, 
LASTNAME);

                assertNotNull(testName);
                assertNotNull(CONTROLNAME);

                assertEquals(CONTROLNAME.getFirstName(), 
testName.getFirstName());
assertEquals(CONTROLNAME.getMiddleInitial(), testName.getMiddleInitial());
                assertEquals(CONTROLNAME.getLastName(), testName.getLastName());

                assertTrue(testName.equals(CONTROLNAME));
        }

        public function testTestFails():Void {
                var testName:Name = new Name(FIRSTNAME, MIDDLEINITIAL, 
LASTNAME);

                assertNotNull(testName);

                assertEquals("Carlos", testName.getFirstName());
                assertEquals("Vizcarondo", testName.getMiddleInitial());
                assertEquals("M.", testName.getLastName());

                assertTrue(testName.equals(new Object()));
        }
        
}

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to