Packageasunit.framework
Classpublic class Assert
InheritanceAssert Inheritance flash.events.EventDispatcher
SubclassesTestCase

A set of assert methods. Messages are only displayed when an assert fails.



Public Methods
 MethodDefined by
  
Protect constructor since it is a static only class
Assert
  
assertEquals(... args):void
[static] Asserts that two objects are equal.
Assert
  
assertEqualsArrays(... args):void
[static] Asserts that two arrays have the same length and contain the same objects in the same order.
Assert
  
[static] Asserts that two arrays have the same length and contain the same objects.
Assert
  
assertEqualsFloat(... args):void
[static] Asserts that two numerical values are equal within a tolerance range.
Assert
  
assertFalse(... args):void
[static] Asserts that a condition is false.
Assert
  
assertNotNull(... args):void
[static] Asserts that an object isn't null.
Assert
  
assertNotSame(... args):void
[static] Asserts that two objects do not refer to the same object.
Assert
  
assertNull(... args):void
[static] Asserts that an object is null.
Assert
  
assertSame(... args):void
[static] Asserts that two objects refer to the same object.
Assert
  
assertThrows(errorType:Class, block:Function):void
[static] Asserts that the provided block throws an exception that matches the type provided.
Assert
  
assertTrue(... args):void
[static] Asserts that a condition is true.
Assert
  
fail(message:String):void
[static] Fails a test with the given message.
Assert
Constructor detail
Assert()constructor
public function Assert()

Protect constructor since it is a static only class

Method detail
assertEquals()method
public static function assertEquals(... args):void

Asserts that two objects are equal. If they are not an AssertionFailedError is thrown with the given message. This assertion should be (by far) the one you use the most. It automatically provides useful information about what the failing values were.

          public function testNames():void {
              var name1:String = "Federico Aubele";
              var name2:String = "Frederico Aubele";
              
              assertEquals(name1, name2);
          }
          

Parameters
... args
assertEqualsArrays()method 
public static function assertEqualsArrays(... args):void

Asserts that two arrays have the same length and contain the same objects in the same order. If the arrays are not equal by this definition an AssertionFailedError is thrown with the given message.

Parameters
... args
assertEqualsArraysIgnoringOrder()method 
public static function assertEqualsArraysIgnoringOrder(... args):void

Asserts that two arrays have the same length and contain the same objects. The order of the objects in the arrays is ignored. If they are not equal by this definition an AssertionFailedError is thrown with the given message.

Parameters
... args
assertEqualsFloat()method 
public static function assertEqualsFloat(... args):void

Asserts that two numerical values are equal within a tolerance range. If they are not an AssertionFailedError is thrown with the given message.

Parameters
... args
assertFalse()method 
public static function assertFalse(... args):void

Asserts that a condition is false. If it isn't it throws an AssertionFailedError with the given message.

Parameters
... args
assertNotNull()method 
public static function assertNotNull(... args):void

Asserts that an object isn't null. If it is an AssertionFailedError is thrown with the given message.

Parameters
... args
assertNotSame()method 
public static function assertNotSame(... args):void

Asserts that two objects do not refer to the same object. If they do, an AssertionFailedError is thrown with the given message.

Parameters
... args
assertNull()method 
public static function assertNull(... args):void

Asserts that an object is null. If it is not an AssertionFailedError is thrown with the given message.

Parameters
... args
assertSame()method 
public static function assertSame(... args):void

Asserts that two objects refer to the same object. If they are not an AssertionFailedError is thrown with the given message.

Parameters
... args
assertThrows()method 
public static function assertThrows(errorType:Class, block:Function):void

Asserts that the provided block throws an exception that matches the type provided.

         public function testFailingCode():void {
            assertThrows(CustomError, function():void {
                  var instance:Sprite = new Sprite();
                  instance.callMethodThatThrows();
            });
         }
         

Parameters
errorType:Class
 
block:Function
assertTrue()method 
public static function assertTrue(... args):void

Asserts that a condition is true. If it isn't it throws an AssertionFailedError with the given message.

Parameters
... args
fail()method 
public static function fail(message:String):void

Fails a test with the given message.

Parameters
message:String

Example
This method can be called anytime you want to break out and fail the current test.
          public function testSomething():void {
              var instance:MyClass = new MyClass();
              if(instance.foo()) {
                  fail('The foo should not have been there');
              }
          }