assertTrue is the professional blog of Luke Bayes and Ali Mills

AsUnit framework 'as2' vs 'as25'?

Posted by: Luke Bayes Tue, 24 Oct 2006 00:10:00 GMT

I just got a really good question on the AsUnit-users mailing list and as I was answering it, the answer kind of turned into a more bloggy-thing, so here goes:

The question:

“Ok. So. If I use the as25 version of the code (asunit vs. com.asunit), I don’t seem to get output to the builtin AsUnit UI panel in the IDE (which i installed via the .mxp). Is there a way to make the builtin UI work with the as25 codebase? If not, what should I be using to see the status of the unit-tests when using the flash IDE?”

This is a great question and I’m really sorry that we haven’t been more clear about what the different AsUnit framework builds are and why they exist…

Read more...

Tags  | no comments

No Try..Catch from EventDispatchers in ActionScript 3.0?

Posted by: Luke Bayes Tue, 17 Oct 2006 20:59:00 GMT

Wow…

I was just doing some work on event handling with AsUnit 3.x and discovered something pretty strange. It seems that if an event handler throws an exception, there is no way to catch it from the initiating thread. For some reason, if an exception makes it to the EventDispatcher, it just passes right through all encountered catch/finally blocks and goes right up to the player as an uncaught exception.

Just copy the following code into a new ActionScript project in FlexBuilder and make it your default application to see this in action:

package {
    import flash.display.Sprite;
    import flash.errors.IllegalOperationError;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;

    public class EventDispatcherTest extends Sprite {

        private var dispatcher:IEventDispatcher;

        public function EventDispatcherTest() {
            runTests();
        }

        public function runTests():void {
            dispatcher = new EventDispatcher();
            dispatcher.addEventListener(Event.CHANGE, someHandler);
            try {
                // Uncomment this line to see the catch work...
                //someHandler(new Event(Event.CHANGE));
                dispatcher.dispatchEvent(new Event(Event.CHANGE));
            }
            catch(error:*) {
                trace("Exception has been caught!");
            }
        }

        private function someHandler(event:Event):void {
            trace("someHandler called");
            throw new IllegalOperationError("AnyException");
        }
    }
}

This will throw an exception up to the player with a call stack that looks like this:

Error: AnyException
    at EventDispatcherTest/EventDispatcherTest::someHandler()[...EventDispatcherTest\EventDispatcherTest.as:31]
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at EventDispatcherTest/runTests()[...EventDispatcherTest\EventDispatcherTest.as:22]
    at EventDispatcherTest$iinit()[...EventDispatcherTest\EventDispatcherTest.as:13]

You can see from the call stack that the exception actually passed through the “runTests” method – but didn’t get caught!

I’m really not sure what to make of this, but I think we’re about to have to roll our own event management!

Those of you using AsUnit 3.x should know that because of this issue, the old recommended way of testing event handlers in AS 2 by throwing an “AssertionPassedError” won’t work in AS 3.

Anyone else run into this? Perhaps there is something simple that we can do differently to avoid this behavior?

Tags , ,  | no comments

Custom Events in ActionScript 3.0

Posted by: Luke Bayes Sun, 15 Oct 2006 06:18:00 GMT

I just lost at least 2 hours to this one and figured I’d share with the hope that maybe I’ll save someone else the same headache…

If you’re working with the Flex 2 framework and writing custom components as directed, you’re probably creating custom event data types.

If your event handlers are written to expect an instance of your custom data type, be sure you override the “clone” method and return a new, configured instance of your new event data type.

I’ve been staring at this error message for hours now:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@148cb29 to lifebin.events.ActionEvent.

It was driving me nuts because the stack trace begins with a method that actually dispatches a correctly configured instance of an ActionEvent!

I even went so far as to create isolated test cases that create, dispatch and bubble custom events through a Flex and non-flex composite structure. I was unable to reproduce the error outside of our application and still don’t know why or whom is calling clone – but I just tried implementing the clone method out of desparation and voila! Everything works.

I’d love to know why this is happening – but for now – I’m content with spreading the word as to how to avoid it!

Good Luck.

Tags  | 3 comments

MAX :: Design Patterns in ActionScript 3

Posted by: Ali Mills Tue, 10 Oct 2006 16:39:00 GMT

In two weeks, Luke and I will be at MAX where we’ll be giving two sessions on Design Patterns in ActionScript 3. The first session is on Wednesday, October 25 from 1:45pm – 2:45pm in rooms 4201 – 4202 of the Lando space. The second is on Thursday, October 26 from 3:00pm – 4:00pm in rooms 4105 – 4106 of the Delfino space. Both Lando and Delfino are on the fourth floor. If you have a Google Calendar account, you can add our session to it by clicking the following buttons:


for Wednesday for Thursday

If you’re registered for MAX, use the MAX Session Scheduler to add our session to your schedule. Lists of all Wednesday and Thursday sessions are posted here and here. If you want something more portable than the MAX Session Scheduler, Bill Perry is soliciting MAX conference guides in Flash Lite that he’ll be uploading to his site as he gets them.

If you haven’t already registered for MAX, you still can! Go to https://www.adobemax06.com/ and do it.

Finally, if you can’t register but are planning to be in Vegas and want to attend something Adobe related, consider attending Ted Patrick’s unconference MAXUP. I’ll be there demonstrating a mobile iCalendar reader project I’m working on. Many other people will be there, too. To sign up for MAXUP, just follow Ted’s instructions.

Tags , , ,  | 3 comments

MAXUP :: Mobile iCalendar Reader is Going to MAX

Posted by: Ali Mills Fri, 06 Oct 2006 19:07:00 GMT

MAXUP is an unconference that will be running parallel to the MAX conference from October 24rd – October 26th at the The Venetian Hotel in Las Vegas, Nevada. I’ve been hearing about these unconference Foo Camp style spin-offs for a little while and like the idea. Since I’ll already be in Vegas presenting at MAX on design patterns in ActionScript 3, I’m going to join all these attendees and participate in MAXUP, too.

At MAXUP I’m going to give a demo of a mobile calendar project I’m working on that reads and presents remote calendar files (specifically iCalendar formatted files) on Flash Lite devices. Like most projects, this one has both a server and client component. The server is written in Ruby and the client in Flash Lite 1.1. I’ll be demonstrating the project running on my Nokia 6600 and Nokia N70 phones, and discuss how it was built. I’ll do my best to follow Scott Berkin’s advice on how to run a great unconference session.

Here are some recent pictures of the calendar running on my N70:

Read more...

Tags , , , , , ,  | 1 comment

Flex2 MXML Project Support in AsUnit

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

[Updated on 10/12/2006 because of changes to the available release]

I’m excited to announce cleaner support for MXML projects in AsUnit!

The latest framework build found in sourceforge svn now has support for Flex applications. This new build allows you to create and run unit tests against visual entities that both do extend UIComponent, and do not extend UIComponent! Just call addChild() in your setUp method and AsUnit will figure out what to do with it.

This is a huge deal if you’re working on Component development because some components may compose visual entities that don’t implement IUIComponent. If you simply build your Application test fixture using the FlexRunner base class, whenever you call addChild() in a TestCase, the framework will determine where to attach that child. If it’s an IUIComponent, it will be attached to the Application directly, if it is not an IUIComponent, it will be attached to the Application.rawChildren array.

Following is an example test Fixture using the latest sources from svn. Just copy the code into a file and name it “ProjectNameRunner.mxml” (replace ProjectName with your project name), and tell FlexBuilder to use that File as the Application root.

<?xml version="1.0" encoding="utf-8"?>
<FlexRunner xmlns="asunit.textui.*" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="runTests()">
    <mx:Style source="../css/Lifebin.css"/>
    <mx:Script>
        <![CDATA[
            import asunit.textui.TestRunner;

            public function runTests():void {
                start(AllTests, null, TestRunner.SHOW_TRACE);
            }
        ]]>
    </mx:Script>
</FlexRunner>

Just manage the start() method the same way you always would in the past and you’re up and running!

A quick explanation of the start method:
start(test:Class, method:String=null, showTrace:Boolean=false):void;

test:Class argument should reference the Class definition of a TestCase or TestSuite – something that implements the Test interface.

method:String=null argument is an optional string name of a single method to execute. This is really important when testing visual entities because if this argument is not null, only the test method identified will be executed and tearDown/cleanUp will not be called. This gives you the ability to actually see and interact with the visual entity while testing. Once it’s working and your tests are passing, leave the argument null so that all test methods will be called.

showTrace:Boolean=false argument will send the TestResult string to the trace window when all tests have finished executing. This argument is great if you’re like me and keep closing the running swf, but then want to see some detail in a failure. It’s also essential for hooking AsUnit up to some external continuous integration tool.

Tags  | no comments

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

HaXe 1.06 :: Flash 7/8 Library Assets in Flash 9

Posted by: Ali Mills Tue, 29 Aug 2006 05:48:00 GMT

Before I’ve even had a chance to experiment with haXe 1.05, verison 1.06 has been released! How long did that take? Maybe a week? Two of the more interesting features of this version are that it supports the use of Flash 7/8 library assets from Flash 9 code and there’s been an addition of a RubyGems like distribution system called haxelib.

You can read about all of the new features and Nicolas’ blog, but here’s a quick glance at the change log:

  • allowed extern enums
  • use only matching construct when parameters are matched
  • fixed bug preventing & char to be sent between JS and Flash remoting
  • improved flash9 api (more strict)
  • flash9 xml : use JS ReXml parser
  • added neko.io package (Input/Output)
  • moved neko.File and neko.Socket to neko.io package
  • fixed flash optional arguments (when extending flash.MC)
  • fixed neko native serialization problems
  • variable modification does not have side effects in ‘for x in a…b’
  • jit disabled by default for neko web server
  • enable flash7-8 libraries usage from flash9
  • unknown identifier become “class not found” when is a classpath
  • changed haxe.PosInfos handling
  • added -debug (removed—flash-debug) on flash9 and neko only now
  • added Type.typeof
  • improved Serializer speed
  • added Serialization support for Date, Hash, IntHash, List
  • added flash9 and JS IE/Opera class reflection
  • added haxe.xml.Check and haxe.xml.Fast
  • added Xml.parent
  • added haxelib
  • added ArrayAccess interface

As always, you can download the latest build from http://www.haxe.org/download.

Tags  | no comments

AS3 Bug When Nesting 'if' Within 'switch'

Posted by: Ali Mills Tue, 29 Aug 2006 05:33:00 GMT

Luke and I ran into an ActionScript 3.0 bug today when nesting an if statement within a switch. It looks like the compiler has problems referencing object properties when this happens. The following code demonstrates what we found:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package {
    import flash.display.Sprite;

    public class SwitchBug extends Sprite {
        public function SwitchBug() {
            var num:Number = 1;
            var firstNumber:Number = num;
            var secondNumber:Number = num;
            tryNumSwitch("go", firstNumber, secondNumber);

            var now:Date = new Date();
            var firstDate:Date = now;
            var secondDate:Date = now;
            tryDateSwitch("go", firstDate, secondDate);            

            // this method causes a crash
            tryCrashingDateSwitch("go", firstDate, secondDate);
        }

        private function tryNumSwitch(val:String, firstNumber:Number, secondNumber:Number):void {
            switch(val) {
                case "go":
                    if(firstNumber == secondNumber) {
                        trace(">> tryNumSwitch successful !!");
                    }
            }
        }

        private function tryDateSwitch(val:String, firstDate:Date, secondDate:Date):void {
            switch(val) {
                case "go":
                    if(firstDate == secondDate) {
                        trace(">> tryDateSwitch successful !!");
                    }
            }
        }

        private function tryCrashingDateSwitch(val:String, firstDate:Date, secondDate:Date):void {
            switch(val) {
                case "go":
                    // the compiler crashes on DATE.milliseconds call
                    if(firstDate.milliseconds == secondDate.milliseconds) {
                        trace(">> tryCrashingDateSwitch successful !!");
                    }
                    // uncommenting the trace below fixes the situation
//                    trace("Fixed");
            }
        }
    }
}

Oddly, adding a trace (or any line of code) after the if statement fixes the issue.

Tags ,  | 2 comments

HaXe Sample Application :: Simple Slide Show

Posted by: Ali Mills Tue, 22 Aug 2006 05:15:00 GMT

If you’ve been reading this blog then it should be clear to you that I’m pretty interested in the haXe programming language (if it’s not clear see: Invest Regulary in Your Knowledge Portfolio, Where’s haXe?, HaXe Found!, and HaXe 1.05 Supports Flash Player 9!). My interest in haXe is rooted in my desire to build universally available applications with a code-base that I can grow.

To learn the haXe syntax and language APIs, I wrote a Simple Slide Show application that I call Mediator. Here it is:

You can download the source here.

Some interesting parts of Mediator follow:
  • the EventDispatcher class demonstrates many elements of the haXe syntax
  • background art is externalized in the FLA art/MediatorAssets.fla
  • slide data is externalized in the XML document xml/Mediator.xml
  • the MediatorModel class demonstrates XML parsing in haXe
  • the entire application has a flexible layout (which you won’t be able to notice unless you download Mediator.zip, run the Mediator.swf on your desktop, and resize it)
  • Events in the application bubble, this is handled by the Component class’s dispatchEvent() method; that method looks like:
    public function dispatchEvent(event:Event):Bool {
        var dispatched:Bool = dispatcher.dispatchEvent(event);
        if(event.bubbles && dispatched && getParent() != null) {
            getParent().dispatchEvent(event);
        }
        return dispatched;
    }

To compile the simple slide show, first download and install haXe, then download Mediator.zip, and after unpacking it double-click build.hxml.

To run the application locally without compiling, just double-click Mediator.swf.

Tags ,  | no comments

Older Posts

Older posts: 1 ... 5 6 7 8 9