assertTrue is the professional blog of Luke Bayes and Ali Mills

Asynchronous Test Methods in AsUnit!

Posted by Luke Bayes Thu, 05 Oct 2006 19:40:00 GMT

Thanks to some gentle prodding from the Eyefodder “Deathmatch” and more than a small handful of requests, We finally got asynchronous test methods working in AsUnit!

We have also introduced much more robust support for Flex 2 applications.

The latest build of AsUnit 3.x (in Subversion only) has these features but we need your help to test them out.

Please pull down the latest sources from sourceforge svn by opening a terminal and performing the following steps: (you must have subversion client installed and available in your path)

mkdir asunit
svn co https://svn.sourceforge.net/svnroot/asunit/trunk/framework/as3 .
(the trailing period will put the files into the current directory without creating another subdirectory).

Here is an example of an asynchronous test method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public function testAsyncFeature():void {
    // create a new object that dispatches events...
    var dispatcher:IEventDispatcher = new EventDispatcher();
    // get a TestCase async event handler reference
    // the 2nd arg is an optional timeout in ms. (default=1000ms )
    var handler:Function = addAsync(changeHandler, 2000);
    // subscribe to your event dispatcher using the returned handler
    dispatcher.addEventListener(Event.CHANGE, handler);
    // cause the event to be dispatched.
    // either immediately:
    //dispatcher.dispatchEvent(new Event(Event.CHANGE));
    // or in the future < your assigned timeout
    setTimeout( dispatcher.dispatchEvent, 200, new Event(Event.CHANGE));
}

protected function changeHandler(event:Event):void {
    // perform assertions in your handler
    assertEquals(Event.CHANGE, event.type);
}

That should be enough to get you going with Asynchronous test methods!

Please let us know on this list if you have any problems.

Thanks,

Luke Bayes

www.asunit.org

Tags  | no comments

Comments

Your Reply

Comment Form.

Fields denoted with an "*" are required.