Flex Open-Source SDK

FlexUnit 4 can be used with the Flex Open Source SDK.

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.

When using a Flash or Flex IDE, a libs folder is automatically created. In this case, create a top level projhect file (ie myProject). Within the top-level directory create a "src" directory for the project source files and a "libs" directory for the project libs. 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 for 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" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:flexui="flexunit.flexui.*"
               xmlns:adobe="http://www.adobe.com/2009/flexUnitUIRunner"
               minWidth="955" minHeight="600" 
               creationComplete="onCreationComplete()">
    <fx:Script>
        <![CDATA[
            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();
                testsToRun.push(tests.MainSuite);
                return testsToRun;
            }


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

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

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.

This application will create an environment that will run tests and display results. You can build it using the following command format::

 /Location-Of-Your-Flex-SDK/bin/mxmlc -library-path+=../libs FlexUnitApplication.mxml

In this case, the "libs" directory should contain the FlexUnit core and UiListener swc files.

Once the swf is complied, run it in a browser window. Here is a sample output in the browser window:

UIListener.PNG