Flash Builder 4 (Standard)

Flash Builder 4 Standard includes the controls for creating and running unit tests, but unfortunately, they are just a tease. When a user selects "Create A New Test Case Class" or "Run FlexUnit Tests," they are merely prompted with a message about how the feature is only implemented in Flash Builder 4 Premium.

Regardless, FlexUnit 4 can still be used within Flash Builder 4 standard, it's just that there are no options for integration with the IDE.

One of the benefits of the IDE integration is that FlexUnitApplication.mxml file is automatically created. For Flash Builder 4 Standard, Flex Builder 3, and Flex Open-Source SDK users, this file must be created manually with some revisions differentiating it from the Flash Builder 4 Premium version.

Download the FlexUnit 4 libraries from FlexUnit.org. You will need the FlexUnit core and FlexUnit UIListener swc files. Drop those into the libs folder of the project.

Create a file in the project named FlexUnitApplication.mxml, here is the form:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               minWidth="955" minHeight="600" 
            import org.flexunit.listeners.UIListener;
            import org.flexunit.runner.FlexUnitCore;

            import tests.MainCase;

            private var core:FlexUnitCore;

            public function currentRunTestSuite():Array
                var testsToRun:Array = new Array();
                return testsToRun;

            private function onCreationComplete():void
                core = new FlexUnitCore();
                core.addListener( new UIListener( testRunnerBase ) );
                core.run( currentRunTestSuite() ); 

        <!-- Place non-visual elements (e.g., services, value objects) here -->
    <adobe:TestRunnerBase id="testRunnerBase" width="100%" height="100%" />

The testsToRun array, created and returned by the currentRunTestSuite() method, should contain all the tests and suites you want to run. In this case, we have used a top-level suite named "MainSuite," this way we only have to add the single suite to the array. The onCreationComplete() method will add the testRunnerBase as the listener for the core variable, when the core runs, the results are output to the browser window in the testRunnerBase display.

Tests are not explicitly run or reported through Flash Builder, as is the case with Flash Builder 4 Premium. Instead, an mxml file for running tests and displaying test results is made. You can then run or debug this application in Flash Builder as needed.

Here is a sample output in the browser window: