Package | org.flexunit.async |
Class | public class Async |
Inheritance | Async ![]() |
Async
class contains static methods used in the handling of events in asynchronous
methods in a particular test case. These methods may be called in an asynchronous test method in
order to exhibit specific behavior once the proper conditions are met.
The asynchronous test methods must be labeled as asynchronous in order
to successfully use Async
's static methods; otherwise, the test will not be registered as
asynchronous and an AssertionError
will be thrown.
[Test(async)]
public function asyncTest():void {
Async.proceedOnEvent(...);
}
Method | Defined By | ||
---|---|---|---|
asyncHandler(testCase:Object, eventHandler:Function, timeout:int, passThroughData:Object = null, timeoutHandler:Function = null):Function [static]
This method works similarly to the handleEvent, however, whereas the handleEvent does all of the work to handle a specific event,
this method simply returns an eventHandler (function) which you use within your own addEventListener() methods. | Async | ||
asyncNativeResponder(testCase:Object, resultHandler:Function, faultHandler:Function, timeout:int, passThroughData:Object = null, timeoutHandler:Function = null):Responder [static]
This method works in a similar fashion to handleEvent, however, it is intended to work with AsyncTokens and Responders as opposed to events. | Async | ||
asyncResponder(testCase:Object, responder:*, timeout:int, passThroughData:Object = null, timeoutHandler:Function = null):IResponder [static] | Async | ||
delayCall(testCase:Object, callback:Function, delay:Number):void [static]
Calls a method after a given delay. | Async | ||
failOnEvent(testCase:Object, target:IEventDispatcher, eventName:String, timeout:int = 500, timeoutHandler:Function = null):void [static]
This method is used when you want to fail if a given event occurs, within a given amount of time, during an asynchronous test. | Async | ||
handleEvent(testCase:Object, target:IEventDispatcher, eventName:String, eventHandler:Function, timeout:int = 500, passThroughData:Object = null, timeoutHandler:Function = null):void [static]
Allow you to continue a test while waiting for a given asynchronous event to occur. | Async | ||
proceedOnEvent(testCase:Object, target:IEventDispatcher, eventName:String, timeout:int = 500, timeoutHandler:Function = null):void [static]
This method is used when you want to ensure that a specific event fires during an asynchronous test. | Async | ||
registerFailureEvent(testCase:Object, target:IEventDispatcher, eventName:String):void [static]
Causes the failure of the existing block (Before, After or the Test itself dependent upon where this statement is located) when an event occurs. | Async |
asyncHandler | () | method |
public static function asyncHandler(testCase:Object, eventHandler:Function, timeout:int, passThroughData:Object = null, timeoutHandler:Function = null):Function
This method works similarly to the handleEvent, however, whereas the handleEvent does all of the work to handle a specific event, this method simply returns an eventHandler (function) which you use within your own addEventListener() methods.
Parameters
testCase:Object — The current asynchronous test case.
| |
eventHandler:Function — The function that will be executed if the timemout period has not been reached.
| |
timeout:int — The length of time, in milliseconds, before the calling the timeoutHandler
if the eventName event is not dispatched.
| |
passThroughData:Object (default = null ) — An Object that can be given information about the current test, this information will be
available to both the eventHandler and timeoutHandler .
| |
timeoutHandler:Function (default = null ) — The function that will be executed if the timeout period is reached.
|
Function |
asyncNativeResponder | () | method |
public static function asyncNativeResponder(testCase:Object, resultHandler:Function, faultHandler:Function, timeout:int, passThroughData:Object = null, timeoutHandler:Function = null):Responder
This method works in a similar fashion to handleEvent, however, it is intended to work with AsyncTokens and Responders as opposed to events.
Parameters
testCase:Object — The current asynchronous test case.
| |
resultHandler:Function — The function that will be executed if the timeout period has not been reached and we have a success.
| |
faultHandler:Function — The function that will be executed if the timeout period has not been reached and we have an error.
| |
timeout:int — The length of time, in milliseconds, before the calling the timeoutHandler
if the eventName event is not dispatched.
| |
passThroughData:Object (default = null ) — An Object that can be given information about the current test, this information will be
available to both the eventHandler and timeoutHandler .
| |
timeoutHandler:Function (default = null ) — The function that will be executed if the timeout period is reached.
|
Responder |
asyncResponder | () | method |
public static function asyncResponder(testCase:Object, responder:*, timeout:int, passThroughData:Object = null, timeoutHandler:Function = null):IResponder
Parameters
testCase:Object | |
responder:* | |
timeout:int | |
passThroughData:Object (default = null )
| |
timeoutHandler:Function (default = null )
|
IResponder |
delayCall | () | method |
public static function delayCall(testCase:Object, callback:Function, delay:Number):void
Calls a method after a given delay.
Parameters
testCase:Object — The current asynchronous test case.
| |
callback:Function — The function that will be executed if the delay has been reached.
| |
delay:Number — The length of time, in milliseconds, before calling the callback .
|
failOnEvent | () | method |
public static function failOnEvent(testCase:Object, target:IEventDispatcher, eventName:String, timeout:int = 500, timeoutHandler:Function = null):void
This method is used when you want to fail if a given event occurs, within a given amount of time, during an asynchronous test. When the event fires,
the flex unit framework causes the test to fail. If the timout is reached before the failure occurs, then the framework will no longer watch for
this event. So, for example, if you want to verify that you do not receive a failure within 300ms, this would be a good method to use.
This method is generally used when the existance of the event, and not the even't data is sufficient to indicate failure. If you need to inspect
the event's data before making a decision, then use handleEvent
instead.
Parameters
testCase:Object — The current asynchronous test case.
| |
target:IEventDispatcher — The target that will listen for the dispatched eventName .
| |
eventName:String — The name of the event being listend for by the target .
| |
timeout:int (default = 500 ) — The length of time, in milliseconds, before the calling the timeoutHandler
if the eventName event is not dispatched.
| |
timeoutHandler:Function (default = null ) — The function that will be executed if the target does not
receive expected eventName before the timeout time is reached.
|
handleEvent | () | method |
public static function handleEvent(testCase:Object, target:IEventDispatcher, eventName:String, eventHandler:Function, timeout:int = 500, passThroughData:Object = null, timeoutHandler:Function = null):void
Allow you to continue a test while waiting for a given asynchronous event to occur. Normally a test ends when you reach the method closure at the end
of your test method. This event tells the FlexUnit framework to continue that test pending the dispatch of an event by the target
of an
event named eventName
. If that event does not occur within the timeOut
then the timeout handler (if specified) will be called,
else the test will be declared a failure.
Parameters
testCase:Object — The current asynchronous test case.
| |
target:IEventDispatcher — The target that will listen for the dispatched eventName .
| |
eventName:String — The name of the event being listend for by the target .
| |
eventHandler:Function — The function that will be executed if the the target dispatches an event with
a name of eventName within the provided timemout period.
| |
timeout:int (default = 500 ) — The length of time, in milliseconds, before the calling the timeoutHandler
if the eventName event is not dispatched.
| |
passThroughData:Object (default = null ) — An Object that can be given information about the current test, this information will be
available to both the eventHandler and timeoutHandler .
| |
timeoutHandler:Function (default = null ) — The function that will be executed if the target does not
receive expected eventName before the timeout time is reached.
|
proceedOnEvent | () | method |
public static function proceedOnEvent(testCase:Object, target:IEventDispatcher, eventName:String, timeout:int = 500, timeoutHandler:Function = null):void
This method is used when you want to ensure that a specific event fires during an asynchronous test. When the event fires, the flex unit
framework simply acknowledges it internally. If there are additional outstanding asynchronous events, those will be processed individually.
This method is generally used when the existance of the event, and not the even't data is sufficient to indicate success. If you need to inspect
the event's data before making a decision, then use handleEvent
instead.
Parameters
testCase:Object — The current asynchronous test case.
| |
target:IEventDispatcher — The target that will listen for the dispatched eventName .
| |
eventName:String — The name of the event being listend for by the target .
| |
timeout:int (default = 500 ) — The length of time, in milliseconds, before the calling the timeoutHandler
if the eventName event is not dispatched.
| |
timeoutHandler:Function (default = null ) — The function that will be executed if the target does not
receive expected eventName before the timeout time is reached.
|
registerFailureEvent | () | method |
public static function registerFailureEvent(testCase:Object, target:IEventDispatcher, eventName:String):void
Causes the failure of the existing block (Before, After or the Test itself dependent upon where this statement is located) when an event occurs. In practice, this method is used to handle an event dispatched from an object under test that, while not necessarily part of the test itself, would indicate a failure if dispatched. A valid example might be an service call. You may want to test that the data is correct and returns within a given period of time, however, if at any time during that test a Failure event is dispatched, you likely wish to end the test.
Parameters
testCase:Object — The current asynchronous test case.
| |
target:IEventDispatcher — The target that will listen for the dispatched eventName .
| |
eventName:String — The name of the event being listend for by the target .
Example:
[Test(async)]
public function doTest():void {
Async.registerFailureEvent( this, httpService, FaultEvent.FAULT );
Async.handleEvent( this, httpService, ResultEvent.RESULT, handleResult, 2000 );
httpService.send();
}
Without the registerFailureEvent, you would need to wait 2 full seconds for the timeout to occur before declaring this test a failure when a fault
event occurs.
|