Package | flexunit.framework |
Class | public class EventfulTestCase |
Inheritance | EventfulTestCase TestCase Assert |
The process of testing the dispatch of events typically involves four stages:
listenForEvent()
function.
assertEvents() function.
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 ); }
Property | Defined by | ||
---|---|---|---|
_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 |
Method | Defined by | ||
---|---|---|---|
EventfulTestCase(methodName:String = null)
| EventfulTestCase | ||
addAsync(func:Function, timeout:int, passThroughData:Object = null, failFunc:Function = null):Function
Add an asynchronous check point to the test.
| TestCase | ||
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 | ||
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 | ||
assertFalse(... rest):void
[static]
Asserts that a condition is false
The first argument can be the message when the assertion fails
| Assert | ||
assertMatch(... rest):void
[static]
Asserts that a string matches a regexp.
| Assert | ||
assertNoMatch(... rest):void
[static]
Asserts that a string doesn't match a regexp.
| Assert | ||
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 | ||
assertNotNull(... rest):void
[static]
Asserts that an object is not null
The first argument can be the message when the assertion fails
| Assert | ||
assertNotUndefined(... rest):void
[static]
Asserts that an object is not undefined
The first argument can be the message when the assertion fails
| Assert | ||
assertNull(... rest):void
[static]
Asserts that an object is null
The first argument can be the message when the assertion fails
| Assert | ||
assertStrictlyEquals(... rest):void
[static]
Asserts that two objects are strickly identical
The first argument can be the message when the assertion fails
| Assert | ||
assertTrue(... rest):void
[static]
Asserts that a condition is true
The first argument can be the message when the assertion fails
| Assert | ||
assertUndefined(... rest):void
[static]
Asserts that an object is undefined
The first argument can be the message when the assertion fails
| Assert | ||
countTestCases():Number
The number of test cases in this test class.
| TestCase | ||
fail(failMessage:String = ""):void
[static]
Fails with the given message
| Assert | ||
getNextAsync():Object
The AsyncTestHelper will call this when it's ready for to start the next async.
| TestCase | ||
getTestMethodNames():Array
| TestCase | ||
hasAsync():Boolean
Returns true if there are any asynchronous methods remaining to be called
| TestCase | ||
oneAssertionHasBeenMade():void
[static]
| Assert | ||
resetAssertionsMade():void
[static]
| Assert | ||
resetEveryAsserionsFields():void
[static]
| Assert | ||
Creates a new
TestResult and runs the tests, populating that TestResult
with the results. | TestCase | ||
runFinish():void
Runs
tearDown()
| TestCase | ||
runMiddle():void
Runs the normal test method or the next asynchronous method
| TestCase | ||
runStart():void
Runs
setUp()
| TestCase | ||
runWithResult(result:TestResult):void
Runs the tests, populating the
result parameter. | TestCase | ||
setTestResult(result:TestResult):void
Called by the TestResult to pass along so that it can be passed for async
| TestCase | ||
setUp():void
Empty implementation of
setUp() . | TestCase | ||
startAsync():void
Called by the TestResult to kick off wait for the next asynchronous method
| TestCase | ||
tearDown():void
Empty implementation of
tearDown() . | TestCase | ||
toString():String
A string representation of the test case
| TestCase |
Method | Defined by | ||
---|---|---|---|
listenForEvent(source:IEventDispatcher, type:String, expected:Boolean):void
Listens for an.
| EventfulTestCase |
Constant | Defined 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 |
dispatchedExpectedEvents | property |
dispatchedExpectedEvents:Array
[read-only]Gets the events that were heard.
Implementation protected function get dispatchedExpectedEvents():Array
lastDispatchedExpectedEvent | property |
lastDispatchedExpectedEvent:Event
[read-only]
Gets the last event to actually be heard. Only expected events
registered through the listenForEvent()
function
can be heard.
protected function get lastDispatchedExpectedEvent():Event
EventfulTestCase | () | constructor |
public function EventfulTestCase(methodName:String = null)
Parameters
methodName:String (default = null )
|
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.
Parametersmessage: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.
Parameterssource: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
|
EVENT_EXPECTED | constant |
public static const EVENT_EXPECTED:Boolean = true
Boolean to indicate the event is expected to be dispatched
EVENT_UNEXPECTED | constant |
public static const EVENT_UNEXPECTED:Boolean = false
Boolean to indicate the event is not expected to be dispatched