views:

52

answers:

1

I am building an app using ActionScript3 with Flash Builder 4 as my IDE.

The IDE supports a unit testing framework called "FlexUnit".

I can build and run tests within the IDE, no problem.

After much pain and suffering I figured out how to build the unit tests as a swf from the command line. I can point a browser or flash player at the swf and the tests run.

But for an automated build system this is no good: I would like to build the tests, run them, and collect/analyze the results to tell which tests, if any, are failing.

I can imaging some hackery: hack FlexUnit base libraries to dump output to stderr instead of just to the IDE console. Hack some script together that points a browser at the swf, counts to 60, kills the browser and checks stderr.

But that's hideous.

I have to believe there's some way to build and run from the command line that works nicely with automated build systems.

Further complication: I am a relative noob with ActionScript (~1 month). My background is C++, makefiles, etc. All the stuff I had to do to get the tests even to build outside the ide (a build.xml file, ant) was complete greek to me, just cut n pasting from examples I could find.

Thanks

A: 

As far as I'm aware your only options for running the swf are in the browser or in the standalone player. Running in the player should not be a problem for your continuous integration environment as long as you can get at the test results and exit the application.

To print test results to stdout you need to add a Text listener to your testunit core instance.

core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) );

To exit the application after the tests have run...

System.exit(0);

For example, your top level mxml file might look like this...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    creationComplete="runMe()" 
    xmlns:adobe="http://www.adobe.com/2009/flexUnitUIRunner"
    >
    <mx:Script>
        <![CDATA[
            import org.flexunit.runner.FlexUnitCore;
            //import org.flexunit.listeners.UIListener;
            //import org.flexunit.listeners.CIListener;
            import org.flexunit.internals.TextListener;
            import mx.logging.LogEventLevel;
            import flash.system.System
            import unit_tests.TestAuthentication.TestAuthentication

            private var core:FlexUnitCore;

            public function runMe():void {
                core = new FlexUnitCore();
                //core.addListener(new UIListener(uiListener));
                //core.addListener(new CIListener());
                core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) );
                core.run( TestAuthentication );
                System.exit(0);
            }
        ]]>
    </mx:Script>
</mx:Application>

Then all you need to do is parse the output. It's not as elegant as we might like but it should work.

Chris

Chris