Packageflexunit.framework
Classpublic class EventfulTestCase
InheritanceEventfulTestCase Inheritance TestCase Inheritance Assert

A base class for test cases that are interested in event dispatching.

The process of testing the dispatch of events typically involves four stages:

  1. Record the events that are expected to occur or not expected to occur during the test case using the listenForEvent() function.
  2. Perform the action under test in the same way as a normal test case.
  3. Assert that the expected events actually occurred using the assertEvents() function.
  4. Assert that the details of these events are correct using the lastDispatchedEvent and dispatchedEvents property getters and standard FlexUnit assertion functions.

An example test case is shown below:

    public function testAddPlutonium() : void
    {
       // record the expected and unexpected events
       listenForEvent( model, TemperatureChangeEvent.TEMPERATURE_CHANGED );
       listenForEvent( model, EmergencyEvent.NUCLEAR_MELTDOWN, UNEXPECTED );
           // perform the action that is being tested
       reactor.addPlutonium( plutonium );
           // assert that the expected events were dispatched and the unexpected
       // events were not dispatched
       assertEvents(
          "The temperature change event was not dispatched or the world has ended" );
           // assert on the details of the actual event
       var temperatureChangeEvent : TemperatureChangeEvent =
          TemperatureChangeEvent( lastDispatchedEvent );
           var expectedTemperature : Number = 550;
           assertEquals(
          "The expected temperature change did not occur.",
          expectedTemperature,
          temperatureChangeEvent.temperature );
    }
    



Public Properties
 PropertyDefined by
 InheritedassertionsMade : Number
TestCase
 InheritedassetionsMade : Number
[static]
Assert
 InheritedclassName : String
Returns the the fully qualified class name
TestCase
 InheritedmaxAssertionsMade : Number
[static]
Assert
 InheritedmethodName : String
The method name of the individual test to be run
TestCase
 InheritedtotalAssertionsMade : Number
[static]
Assert
Protected Properties
 PropertyDefined by
 Inherited_assertionsMade : Number = 0
[static]
Assert
  dispatchedExpectedEvents : Array
[read-only] Gets the events that were heard.
EventfulTestCase
  lastDispatchedExpectedEvent : Event
[read-only] Gets the last event to actually be heard.
EventfulTestCase
Public Methods
 MethodDefined by
  
EventfulTestCase(methodName:String = null)
EventfulTestCase
 Inherited
addAsync(func:Function, timeout:int, passThroughData:Object = null, failFunc:Function = null):Function
Add an asynchronous check point to the test.
TestCase
 Inherited
assertContained(... rest):void
[static] Asserts that the first string is contained in the second one The first argument can be the message when the assertion fails
Assert
 Inherited
assertEquals(... rest):void
[static] Asserts that 2 values are equal.
Assert
  
assertEvents(message:String = ""):void
Asserts that the expected events were dispatched and the unexpected events were not dispatched.
EventfulTestCase
 Inherited
assertFalse(... rest):void
[static] Asserts that a condition is false The first argument can be the message when the assertion fails
Assert
 Inherited
assertMatch(... rest):void
[static] Asserts that a string matches a regexp.
Assert
 Inherited
assertNoMatch(... rest):void
[static] Asserts that a string doesn't match a regexp.
Assert
 Inherited
assertNotContained(... rest):void
[static] Asserts that the first string is not contained in the second one The first argument can be the message when the assertion fails
Assert
 Inherited
assertNotNull(... rest):void
[static] Asserts that an object is not null The first argument can be the message when the assertion fails
Assert
 Inherited
assertNotUndefined(... rest):void
[static] Asserts that an object is not undefined The first argument can be the message when the assertion fails
Assert
 Inherited
assertNull(... rest):void
[static] Asserts that an object is null The first argument can be the message when the assertion fails
Assert
 Inherited
assertStrictlyEquals(... rest):void
[static] Asserts that two objects are strickly identical The first argument can be the message when the assertion fails
Assert
 Inherited
assertTrue(... rest):void
[static] Asserts that a condition is true The first argument can be the message when the assertion fails
Assert
 Inherited
assertUndefined(... rest):void
[static] Asserts that an object is undefined The first argument can be the message when the assertion fails
Assert
 Inherited
countTestCases():Number
The number of test cases in this test class.
TestCase
 Inherited
fail(failMessage:String = ""):void
[static] Fails with the given message
Assert
 Inherited
getNextAsync():Object
The AsyncTestHelper will call this when it's ready for to start the next async.
TestCase
 Inherited
TestCase
 Inherited
hasAsync():Boolean
Returns true if there are any asynchronous methods remaining to be called
TestCase
 Inherited
[static]
Assert
 Inherited
[static]
Assert
 Inherited
[static]
Assert
 Inherited
Creates a new TestResult and runs the tests, populating that TestResult with the results.
TestCase
 Inherited
runFinish():void
Runs tearDown()
TestCase
 Inherited
runMiddle():void
Runs the normal test method or the next asynchronous method
TestCase
 Inherited
runStart():void
Runs setUp()
TestCase
 Inherited
Runs the tests, populating the result parameter.
TestCase
 Inherited
Called by the TestResult to pass along so that it can be passed for async
TestCase
 Inherited
setUp():void
Empty implementation of setUp().
TestCase
 Inherited
startAsync():void
Called by the TestResult to kick off wait for the next asynchronous method
TestCase
 Inherited
tearDown():void
Empty implementation of tearDown().
TestCase
 Inherited
toString():String
A string representation of the test case
TestCase
Protected Methods
 MethodDefined by
  
listenForEvent(source:IEventDispatcher, type:String, expected:Boolean):void
Listens for an.
EventfulTestCase
Public Constants
 ConstantDefined by
  EVENT_EXPECTED : Boolean = true
[static] Boolean to indicate the event is expected to be dispatched
EventfulTestCase
  EVENT_UNEXPECTED : Boolean = false
[static] Boolean to indicate the event is not expected to be dispatched
EventfulTestCase
Property detail
dispatchedExpectedEventsproperty
dispatchedExpectedEvents:Array  [read-only]

Gets the events that were heard.

Implementation
    protected function get dispatchedExpectedEvents():Array
lastDispatchedExpectedEventproperty 
lastDispatchedExpectedEvent:Event  [read-only]

Gets the last event to actually be heard. Only expected events registered through the listenForEvent() function can be heard.

Implementation
    protected function get lastDispatchedExpectedEvent():Event
Constructor detail
EventfulTestCase()constructor
public function EventfulTestCase(methodName:String = null)Parameters
methodName:String (default = null)
Method detail
assertEvents()method
public function assertEvents(message:String = ""):void

Asserts that the expected events were dispatched and the unexpected events were not dispatched. The events must first be recorded using the listenForEvents() method.

Parameters
message:String (default = "") — the user message to display when a test failure occurs
listenForEvent()method 
protected function listenForEvent(source:IEventDispatcher, type:String, expected:Boolean):void

Listens for an. When the assertEvents() function is called, the events will be compared with the actual events.

Parameters
source:IEventDispatcher — the object that is to be listened on for the dispatched event
 
type:String — the type of event that the source object might dispatch
 
expected:Boolean — whether the event is expected to be dispatched or now; defaults to EVENT_EXPECTED
Constant detail
EVENT_EXPECTEDconstant
public static const EVENT_EXPECTED:Boolean = true

Boolean to indicate the event is expected to be dispatched

EVENT_UNEXPECTEDconstant 
public static const EVENT_UNEXPECTED:Boolean = false

Boolean to indicate the event is not expected to be dispatched